PHP file_get_contents error on CentOS

6,839

Solution 1

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

Solution 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.

Share:
6,839

Related videos on Youtube

Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin over 1 year

    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.

  • iKarampa
    iKarampa almost 15 years
    Hi Maxwell, allow_url_fopen is already on and I'm still getting errors.
  • Maxwell
    Maxwell almost 15 years
    They're maybe filtering the User-Agent http header, you may try something like ini_set("user_agent", "xxxxx").
  • iKarampa
    iKarampa almost 15 years
    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..
  • bumperbox
    bumperbox almost 15 years
    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
  • iKarampa
    iKarampa almost 15 years
    hi bumperbox thanks for the reminder. yes i checked phpinfo and it's the correct php.ini
  • fjuan
    fjuan almost 15 years
    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
  • temirbek
    temirbek over 4 years
    is it forever or just for current session?