PHP file_get_contents error on CentOS
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.
Related videos on Youtube
Admin
Updated on September 17, 2022Comments
-
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.
-
lexsys almost 15 yearsWhat is your PHP version?
-
Andy almost 15 yearsCan you wget mirror.facebook.net/centos/timestamp.txt ??
-
Admin almost 15 yearsLexsys: it's 5.1.6 Andy: yes I can.
-
-
iKarampa almost 15 yearsHi Maxwell, allow_url_fopen is already on and I'm still getting errors.
-
Maxwell almost 15 yearsThey're maybe filtering the User-Agent http header, you may try something like ini_set("user_agent", "xxxxx").
-
iKarampa almost 15 yearsI 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 almost 15 yearsdid 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 almost 15 yearshi bumperbox thanks for the reminder. yes i checked phpinfo and it's the correct php.ini
-
fjuan almost 15 yearsI 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 over 4 yearsis it forever or just for current session?