|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74095 Using flush() while php://input is open causes PHP to hang
Submitted: 2017-02-14 14:13 UTC Modified: 2018-06-24 04:25 UTC
From: viskoo at gmail dot com Assigned:
Status: No Feedback Package: Output Control
PHP Version: 7.1.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
35 - 19 = ?
Subscribe to this entry?

 [2017-02-14 14:13 UTC] viskoo at gmail dot com
If you open stdin, to read the body of a PUT request, echo some strings, and then use flush() to flush the output buffer, PHP will hang after reading 192 kbytes from the input stream, on the next flush() call.

This only happens if it's the stdin stream that is open, and not with any other (eg. random local file) stream, and it always happens after reading 48 * 4096 bytes.

You will need a web server (I tested with nginx) configured, to test this.

Test script:
$file = 'php://input';
$stream = fopen($file, 'r');

fopen($file, 'rb');
header('X-Accel-Buffering: no'); // tell nginx not to buffer
$count = 0;
while ($chunk = fread($stream, 4096)) {
    echo "Read some chunks: $count\n";
    flush(); // this is the call that hangs, if you remove this, the script runs fine
echo("Script finished");

Expected result:
Read some chunks: 1
Read some chunks: 2
Read some chunks: 3
Read some chunks: 4
Script finished

Actual result:
Read some chunks: 1
Read some chunks: 2
Read some chunks: 3
Read some chunks: 4
Read some chunks: 48

*hangs until timeout*


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-14 14:21 UTC] viskoo at gmail dot com
Forgot to include the command to test:

curl -XPUT --data-binary @some_large_file.txt http://localhost:1234/
 [2018-06-14 11:12 UTC]
-Status: Open +Status: Feedback
 [2018-06-14 11:12 UTC]
Cannot reproduce on 7.2 with nginx+fpm nor apache2+mod_php.
 [2018-06-24 04:25 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 17:01:31 2024 UTC