I have a strange problem.
Assume my server is example.com. I put a simple script called test.php to www root (assume that /home/example/):
<?php
var_dump(file_get_contents("http://example.com/"));
Open http://example.com/test.php, it shows:
Warning: file_get_contents(http://example.com/) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/example/test.php on line 2
But I can visit http://example.com/ via my browser. wget http://example.com/ and php -r 'var_dump(file_get_contents("http://example.com/"));' both works well on ssh terminal.
My server is CentOS 5.7 + lighttpd 1.4.29 + PHP 5.2.17
http://example.com/andhttp://example.com/test.php. I suppose that's not your source of frustration? – poplitea Dec 27 '11 at 9:32allow_url_fopenis set toOn. Also check it from the command line like this:php -i | grep allow_url_fopen. I suspect your Apache and Command line versions of PHP are not using the same php.ini file. You can find which file they are both using withphp -i | grep php.iniand looking at the "Configuration File" section of the phpinfo() page. – Ladadadada Dec 27 '11 at 11:55