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

link|improve this question
You refer both http://example.com/ and http://example.com/test.php. I suppose that's not your source of frustration? – poplitea Dec 27 '11 at 9:32
Do you possibly not have dns/routes to "yourself"? Maybe just access your local system with file_get_contents("localhost";)? – Mbrevda Dec 27 '11 at 11:52
2  
Create a phpinfo() page and check that allow_url_fopen is set to On. 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 with php -i | grep php.ini and looking at the "Configuration File" section of the phpinfo() page. – Ladadadada Dec 27 '11 at 11:55
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.