Edit report at https://bugs.php.net/bug.php?id=61336&edit=1
ID: 61336 Comment by: s...@php.net Reported by: ram...@php.net Summary: file_get_contents() no longer returns false on 4xx responses Status: Open Type: Bug Package: Filesystem function related Operating System: CentOS 6.2 PHP Version: 5.4.0 Block user comment: N Private report: N New Comment: Just for the record, repro script works for me on Windows / 5.4.0 VC9 NTS Previous Comments: ------------------------------------------------------------------------ [2012-03-09 21:59:47] ram...@php.net 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 this bug report at https://bugs.php.net/bug.php?id=61336&edit=1