|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-22 17:16 UTC] ddrewery at gmail dot com
Description: ------------ Anytime I try accessing an external file via wrappers (fopen, file_get_contents,...), I get "failed to open stream: HTTP request failed!". I have "allow_url_fopen = On" and phpinfo() shows this is correct. It doesn't matter what file, if its not on the local server, it will not work.. even trying to load google.com.. same result. I have two identical servers, both using FC6.. I upgraded from 5.1.6 to 5.2 on one of them and still have the same issue. I currenly have ZEND Optomizer enabled but I installed it after this issue stated (thinking it may help). I can use fsocketopen and make the code work just fine, but anything using fopen wrappers fails. SELinux is disabled on this machine as well. http://teton1w.tetonsolutions.com/geo/yh/phpinfo.php Reproduce code: --------------- <?php function loadXFile($location) { $q = $location; $tmp = file_get_contents($q); return $tmp; } print loadXFile("http://www.google.com"); ?> Actual result: -------------- Warning: file_get_contents(http://www.google.com) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/twhomes/httpdocs/geo/yh/test2.php on line 4 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
How to reproduce it? # php -r 'var_dump(strlen(file_get_contents("http://google.com")));' int(3171)I run that and get this.. # php -r 'var_dump(strlen(file_get_contents("http://google.com")));' PHP Warning: file_get_contents(http://google.com): failed to open stream: HTTP request failed! in Command line code on line 1 Warning: file_get_contents(http://google.com): failed to open stream: HTTP request failed! in Command line code on line 1 int(0)Ok, its being blocked by the firewall.. however I still confused at why. Port 80 is wide open and fsockets work fine. $location = "www.google.com"; $fp = fsockopen($location, 80, $errno, $errstr, 30); $out = "GET / HTTP/1.1\r\n"; $out .= "Host: ".$location."\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); print $result; That works fine $location = "http://www.google.com"; $result = file_get_contents($location); That does not work. Does file_get_contents() use anything other than port 80 for http requests??I've got the error when I use this ``` D:\Folder>php -r 'file_get_contents("http://packagist.org/p/symfony/var-dumper%24ea3512377b773427554949beddf0ed0f9a6c6f43ba6069419cde361083f78a3c.json");' Parse error: syntax error, unexpected end of file in Command line code on line 1 ``` And everything is well if I replace quotes ``` D:\Folder>php -r "file_get_contents('http://packagist.org/p/symfony/var-dumper%24ea3512377b773427554949beddf0ed0f9a6c6f43ba6069419cde361083f78a3c.json');" ``` What is the problem?