0

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.

4 Answers4

2

My first reaction is that this is most likely SELinux that's keeping your PHP scripts from making an outbound network connection. This is enabled by default to help increase security. You can typically enable this functionality by typing

setsebool -P httpd_can_network_connect 1
jsmith
  • 39
  • 2
2

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.

Mohammed Naser
  • 197
  • 2
  • 3
0

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

Maxwell
  • 5,076
  • 1
  • 26
  • 31
  • Hi Maxwell, allow_url_fopen is already on and I'm still getting errors. –  Jun 26 '09 at 08: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 08: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.. –  Jun 26 '09 at 08: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 08:59
  • hi bumperbox thanks for the reminder. yes i checked phpinfo and it's the correct php.ini –  Jun 26 '09 at 09:09
0

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"));'
StackKrish
  • 370
  • 1
  • 6
  • I still get this error: Warning: file_get_contents(http://mirror.facebook.net/centos/timestamp.txt): failed to open stream: HTTP request failed! in Command line code on line 1 –  Jun 29 '09 at 00:37