Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
file_get_contents(http://mirror.facebook.net/centos/timestamp.txt) [function.file-get-contents]: failed to open stream: HTTP request failed!

errors on a freshly installed CentOS 5.3 box. What seems to be the problem?

[Edit] I can get files using wget and my site can fetch RSS feeds but when I try file_get_contents() I get the error above. I don't want to change it because it's in the core of the Joomla! CMS that I'm using.

Thanks in advance :)

[Edit 2] I updated PHP to 5.2.10 and it's still the same.

share|improve this question
    
What is your PHP version? –  lexsys Jun 26 '09 at 9:01
    
Can you wget mirror.facebook.net/centos/timestamp.txt ?? –  Andy Jun 26 '09 at 13:16
    
Lexsys: it's 5.1.6 Andy: yes I can. –  alimango Jun 29 '09 at 0:33

4 Answers 4

This will help you (and us) find out the problem exactly

strace php -r 'print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));'

Make sure that strace is installed and paste the output here, shouldn't be too long, and you might just see some errors yourself and find the reason of this.

If you can't locate the problem, please post the output of strace here and it'll be much easier to locate the problem.

share|improve this answer

After some searching it seems that you must ensure that allow_url_fopen is enabled in your php.ini.

share|improve this answer
    
Hi Maxwell, allow_url_fopen is already on and I'm still getting errors. –  alimango Jun 26 '09 at 8:09
    
They're maybe filtering the User-Agent http header, you may try something like ini_set("user_agent", "xxxxx"). –  Maxwell Jun 26 '09 at 8:36
    
I set the user_agent and it's still not working. I also did HostNameLookups on on my httpd.conf (according to a website) and its still not working.. –  alimango Jun 26 '09 at 8:41
    
did you make sure you are changing the correct php.ini, sometimes there can be several and you might be updating the wrong one. do a phpinfo() if you are not sure, and it will list the correct location of the php.ini file you are using –  bumperbox Jun 26 '09 at 8:59
    
hi bumperbox thanks for the reminder. yes i checked phpinfo and it's the correct php.ini –  alimango Jun 26 '09 at 9:09

To me this sounds mostly like a connection issue. Does the box depend on any proxy to connect to the internet?

I would second Andy's suggestion in the comment to try wget first to establish that there is no connection issues.

Also try a simple test using PHP CLI.

php -r 'print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));'
share|improve this answer
    
I still get this error: Warning: file_get_contents(mirror.facebook.net/centos/timestamp.txt): failed to open stream: HTTP request failed! in Command line code on line 1 –  alimango Jun 29 '09 at 0:37

My first reaction is that this is most likely SELinux that's keeping your PHP scripts from making an outbound network connection. You can typically enable this functionality by typing "setsebool -P httpd_can_network_connect 1".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.