Bug #60465 [ReO]: file_get_contents doesn't stop retrieving data

From: Date: Tue, 20 Jul 2021 12:56:48 +0000
Subject: Bug #60465 [ReO]: file_get_contents doesn't stop retrieving data
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235211@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60465&edit=1 ID: 60465 Updated by: cmb@php.net Reported by: dbc334 at gmail dot com Summary: file_get_contents doesn't stop retrieving data Status: Re-Opened Type: Bug Package: HTTP related Operating System: Windows PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-07-26 12:36:50] 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: <?php header("Content-Length: 1"); print '12'; flush(); ?> 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". ------------------------------------------------------------------------ [2014-07-26 05:17:21] 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-13 10:40:06] dbc334 at gmail dot com This still doesn't work as it should on 5.5.14 (Windows). ------------------------------------------------------------------------ [2014-07-13 01:52:56] yohgaki@php.net Oops. This bug report is for infinite read. Anyway, 5.4 and 5.5 finish reading it. Closing bug. ------------------------------------------------------------------------ [2014-07-13 01:46:35] yohgaki@php.net file_get_contents() has maxlen parameter now. http://php.net/manual/en/function.file-get-contents.php I guess this could be closed. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=60465 -- Edit this bug report at https://bugs.php.net/bug.php?id=60465&edit=1

« previous php.bugs (#235211) next »