PHP 5 Unable to Open HTTP Request Stream with fopen or fsockopen Functions

With Apache/2.x.x or Apache/2.2.x webserver, with PHP5 as the scripting module, a HTTP communication error may occur within the PHP scripts that are parsing and running via the web server.

The errors that generated by PHP include:

PHP Warning: fopen(http://www.example.com): failed to open stream: HTTP request failed!
fsockopen(): unable to connect to …
file_get_contents(): failed to open stream: HTTP request failed!
PHP Warning: main(): Failed opening ‘http://www.example.com/index.html’ for inclusion …
PHP Warning: include(/usr/local/index.php): failed to open stream: No such file or directory in …

To resolve the problem, ensure that allow_url_fopen is enabled in PHP.INI configuration file. The line should look like this:

allow_url_fopen = On

Note: Depending on your system OS and configuration, the PHP.INI is located at various varied location, such as in Apache bin directory for Windows system or /usr/local/etc in FreeBSD Apache installation, if you don’t specify or point to PHP.INI in another directory.

If the error still happen and the PHP scripts still unable to connect to remote external servers and thus unable to download updates or retrieve files, check the user_agent setting in PHP.ini.

By default php.ini set the user_agent to “PHP” which signifies that it’s the script that try to access the web server. Some web servers will refuse and don’t allow script to access and receive the date from the server. So, by setting the user_agent to that of a web browser, PHP will let the web server know which kind of web browser will receive the date, and thus able to open the HTTP connection stream.

The user_agent can be set to any kind of browser strings, for example of Internet Explorer:

user_agent=”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”


5 Responses to “PHP 5 Unable to Open HTTP Request Stream with fopen or fsockopen Functions”

  1. Tarandeep
    March 28th, 2009 00:40
    5

    It did not work for me…

  2. Vladimir
    February 25th, 2009 15:05
    4

    Thank you a lot for info.
    Things with
    user_agent=”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”
    helped

  3. Rob
    November 30th, 2008 03:22
    3

    I solved the problem too. Default parameter on Sme Server 7.3 allow_url_fopen = Off .. Thank you :)

  4. Module
    November 14th, 2008 20:51
    2

    Or you can use curl as described here: http://toic.org/2008/10/08/fetching-remote-content-with-curl/#more-52

  5. totoro
    October 6th, 2008 05:33
    1

    thank you, I solved my problem.
    by default, on openbsd allow_url_fopen = off

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

failed to open stream: HTTP request failed! - failed to open stream: HTTP request failed - file_get_contents failed to open stream - fsockopen php.ini - enable fsockopen - php http request - failed to open stream: HTTP request failed! - php enable fsockopen - fsockopen php ini - file_get_contents php.ini - fsockopen enable - file_get_contents failed to open stream: HTTP request failed! - enable fsockopen php - php.ini fsockopen - php5 fsockopen - fsockopen php5 - fopen HTTP request failed - enable file_get_contents - HOW TO ENABLE FSOCKOPEN - fopen php.ini - enable fopen - php open stream - apache fsockopen - php httprequest - "failed to open stream: HTTP request failed!" - php fsockopen https - file_get_contents HTTP request failed - php fsockopen http - php open http stream - enable fsockopen php.ini - fopen failed to open stream: HTTP request failed! - failed to open stream HTTP request failed - php.ini fopen - php ini fopen - fsockopen apache - fopen php5 - user_agent php.ini - open stream php - enable fsockopen() - allow_url_fopen fsockopen - failed to open stream: HTTP request failed - php.ini user_agent - php HTTP request failed - failed to open stream: HTTP request failed file_get_contents - php file_get_contents HTTP request failed - fsockopen php enable - php http request fopen - fopen php 5 - fsockopen() in php - php fsockopen windows - php5 HttpRequest - file_get_contents failed to open stream: HTTP request failed - php open http request - php5 http request - php fopen http - fsockopen php 5 - fopen cannot connect to urls (PHP parameter allow_url_fopen is set to Off) - php file_get_contents failed to open stream: HTTP request failed! - php fopen failed to open stream http request failed - php allow fsockopen - file_get_contents "failed to open stream: HTTP request failed!" - fsockopen in php - fsockopen() enable - http request stream - php disable fsockopen - php stream open - failed to open stream: HTTP request failed! HTTP - file_get_contents failed to open stream - php http stream - failed to open stream: HTTP request failed! - php5 fopen - file_get_contents failed to open stream http request failed - php fsockopen php.ini - php.ini file_get_contents - HttpRequest php5 -