Bug #74095 [Opn->Fbk]: Using flush() while php://input is open causes PHP to hang
Edit report at https://bugs.php.net/bug.php?id=74095&edit=1
ID: 74095
Updated by: mike@php.net
Reported by: viskoo at gmail dot com
Summary: Using flush() while php://input is open causes PHP
to hang
-Status: Open
+Status: Feedback
Type: Bug
Package: Output Control
Operating System: Linux
PHP Version: 7.1.1
Block user comment: N
Private report: N
New Comment:
Cannot reproduce on 7.2 with nginx+fpm nor apache2+mod_php.
Previous Comments:
------------------------------------------------------------------------
[2017-02-14 14:21:55] viskoo at gmail dot com
Forgot to include the command to test:
curl -XPUT --data-binary @some_large_file.txt http://localhost:1234/
------------------------------------------------------------------------
[2017-02-14 14:13:29] 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*
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74095&edit=1
Thread (4 messages)