|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60465 file_get_contents doesn't stop retrieving data
Submitted: 2011-12-08 00:22 UTC Modified: 2021-09-29 10:26 UTC
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: dbc334 at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: HTTP related
PHP Version: 5.3.8 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dbc334 at gmail dot com
New email:
PHP Version: OS:


 [2011-12-08 00:22 UTC] dbc334 at gmail dot com
When I send request to script connection_close.php from web browser (Internet Explorer, Firefox or Opera), it returns only "1". connection_close.php is run on Apache 2.2 web server.

But when I execute this script from other php file via file_get_contents (eg. do_request.php), it returns "12".

Test script:
file connection_close.php:
print '1';
header("Connection: close");
header("Content-Length: 1");

print '2';

file do_request.php:
print file_get_contents("http://web_server_path/connection_close.php");

Expected result:
Executing do_request.php should return "1".

Actual result:
do_request.php returns "12".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-13 04:14 UTC]
it seems improper to use php_steam_eof while parsing header in 
 [2011-12-13 04:14 UTC]
-Status: Open +Status: Analyzed
 [2011-12-20 02:26 UTC]
-Assigned To: +Assigned To: rasmus
 [2011-12-20 02:26 UTC]
Rasmus, plz look at this one, thanks
 [2014-07-13 01:46 UTC]
file_get_contents() has maxlen parameter now.

I guess this could be closed.
 [2014-07-13 01:52 UTC]
-Status: Analyzed +Status: Closed
 [2014-07-13 01:52 UTC]
Oops. This bug report is for infinite read.
Anyway, 5.4 and 5.5 finish reading it.
Closing bug.
 [2014-07-13 10:40 UTC] dbc334 at gmail dot com
This still doesn't work as it should on 5.5.14 (Windows).
 [2014-07-15 10:30 UTC]
-Status: Closed +Status: Re-Opened
 [2014-07-26 05:17 UTC] cfowler at microsoft dot com
It seems that if you make a call to ob_status() before ob_end_flush() the expected result occurs (the remainder of the script goes unexecuted).
 [2014-07-26 12:36 UTC] dbc334 at gmail dot com
If you move ob_status() three lines downwards (so it's before ob_end_flush()), you will get warning because headers were sent after some content was flushed (this happens when output_buffering is off, which is PHP's default setting).

If you change the value of Content-Length from 1 to 2, browsers will display "12" (which is expected).

Even simpler test script:
header("Content-Length: 1");
print '12';

I have run this and original test script on several servers from the browser. They gave the same results as follows:

Displayed "1" on the following configurations:
PHP 5.3.3 with Apache 2.2.15 (CentOS)
PHP 5.3.23 with Apache (unknown version, unknown linux)
PHP 5.3.28 with Apache (unknown version, unknown linux)
PHP 5.4.17 with Apache 2.2.3 (CentOS)
PHP 5.5.11 with Apache 2.4.9 (Win32)
PHP 5.5.15 with Apache 2.4.10 (Win32)

But it displayed "12" on the following configuration:
PHP 5.2.17 with Apache (unknown version, unknown linux)
(request returned header Content-Length with the value 2 instead of 1)

(I monitored all requests with Fiddler and in all requests browsers got "12" in the body of the request.)

Also: if you remove flush(), the value of Content-Length header changes from 1 to 2 and browsers display "12".
 [2015-02-01 04:26 UTC]
-Assigned To: rasmus +Assigned To:
 [2021-07-20 12:56 UTC]
The problem is that the HTTP stream wrappers ignore the
Content-Length and just read until the stream is EOL.  As such, it
is the same root cause as bug #80931.
 [2021-09-29 10:26 UTC]
-Status: Re-Opened +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-09-29 10:26 UTC]
I'm closing this as duplicate of bug #80931.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 07:01:28 2024 UTC