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)”

Share and contribute or get technical support and help at My Digital Life Forums.



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 without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

failed to open stream: HTTP request failed! - failed to open stream: HTTP request failed - fsockopen php.ini - file_get_contents failed to open stream - enable fsockopen - failed to open stream: HTTP request failed! - file_get_contents php.ini - php http request - how to enable fsockopen - fsockopen php - php.ini fsockopen - php httprequest - fsockopen enable - fsockopen PHP5 - file_get_contents failed to open stream: HTTP request failed! - php enable fsockopen - php5 fopen - fopen http request failed - php5 fsockopen - php open stream - httprequest php - "failed to open stream: HTTP request failed!" - failed to open stream: HTTP request failed! - fopen failed to open stream: HTTP request failed! - php.ini fsock - fopen failed to open stream HTTP request failed - php open http - fopen php.ini - fsockopen() enable - failed to open stream HTTP request failed - fsockopen in php - "failed to open stream: HTTP request failed" - failed to open stream: HTTP request failed! in - fsockopen+php.ini - php.ini fopen - fsockopen php ini - php HTTP request failed - enable fsockopen in php - PHP open http stream - fopen failed to open stream: HTTP request failed - php file_get_contents HTTP request failed - failed to open stream file_get_contents - enable file_get_contents - failed to open stream: HTTP request failed - file_get_contents http request failed - php fsockopen site index - file_get_contents php ini - http request php - php 5 failed to open stream - file_get_contents HTTP request failed! -