php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: viskoo at gmail dot com
New email:
PHP Version: OS:

 

 [2017-02-14 14:13 UTC] viskoo at gmail dot com
Description:
------------
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:
---------------
<?php
$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)) {
    $count++;
    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*

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] mike@php.net
-Status: Open +Status: Feedback
 [2018-06-14 11:12 UTC] mike@php.net
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: Fri Apr 26 19:01:29 2024 UTC