From: ramsey Operating system: CentOS 6.2 PHP version: 5.4.0 Package: Filesystem function related Bug Type: Bug Bug description:file_get_contents() no longer returns false on 4xx responses
Description: ------------ In PHP 5.3, file_get_contents() returns false on 4xx responses. In PHP 5.4, file_get_contents() is returning the actual response body, rather than false. Test script: --------------- <?php $response = file_get_contents('http://us3.php.net/manual/en/function.foobar.php'); var_dump($http_response_header); var_dump($response); Expected result: ---------------- With warnings turned on, this is what I get in PHP 5.3 and what I expect to see in PHP 5.4: PHP Warning: file_get_contents(http://us3.php.net/manual/en/function.foobar.php): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /Users/ramsey/Desktop/file_get_contents.php on line 3 PHP Stack trace: PHP 1. {main}() /Users/ramsey/Desktop/file_get_contents.php:0 PHP 2. file_get_contents() /Users/ramsey/Desktop/file_get_contents.php:3 array(11) { [0]=> string(22) "HTTP/1.0 404 Not Found" [1]=> string(35) "Date: Fri, 09 Mar 2012 21:57:32 GMT" [2]=> string(29) "Server: Apache/2.2.3 (CentOS)" [3]=> string(23) "X-Powered-By: PHP/5.3.2" [4]=> string(20) "Content-language: en" [5]=> string(88) "Set-Cookie: LAST_LANG=en; expires=Sat, 09-Mar-2013 21:57:32 GMT; path=/; domain=.php.net" [6]=> string(102) "Set-Cookie: COUNTRY=USA%2C64.2.187.194; expires=Fri, 16-Mar-2012 21:57:32 GMT; path=/; domain=.php.net" [7]=> string(21) "Status: 404 Not Found" [8]=> string(20) "Content-Length: 4219" [9]=> string(17) "Connection: close" [10]=> string(37) "Content-Type: text/html;charset=utf-8" } bool(false) Actual result: -------------- array(11) { [0]=> string(22) "HTTP/1.1 404 Not Found" [1]=> string(35) "Date: Fri, 09 Mar 2012 21:58:44 GMT" [2]=> string(29) "Server: Apache/2.2.3 (CentOS)" [3]=> string(23) "X-Powered-By: PHP/5.3.2" [4]=> string(20) "Content-language: en" [5]=> string(88) "Set-Cookie: LAST_LANG=en; expires=Sat, 09-Mar-2013 21:58:44 GMT; path=/; domain=.php.net" [6]=> string(102) "Set-Cookie: COUNTRY=USA%2C64.2.187.194; expires=Fri, 16-Mar-2012 21:58:44 GMT; path=/; domain=.php.net" [7]=> string(21) "Status: 404 Not Found" [8]=> string(20) "Content-Length: 4219" [9]=> string(17) "Connection: close" [10]=> string(37) "Content-Type: text/html;charset=utf-8" } string(4219) "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP: 404 Not Found</title> <style type="text/css" media="all"> @import url("/styles/site.css"); @import url("/styles/mirror.css"); ... The rest of the HTML output from the php.net 404 page. -- Edit bug report at https://bugs.php.net/bug.php?id=61336&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61336&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61336&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61336&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61336&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61336&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61336&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61336&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61336&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61336&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61336&r=support Expected behavior: https://bugs.php.net/fix.php?id=61336&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61336&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61336&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61336&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61336&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61336&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61336&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61336&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61336&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61336&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61336&r=mysqlcfg