Bug #74095 [NEW]: Using flush() while php://input is open causes PHP to hang

From: Date: Tue, 14 Feb 2017 14:13:35 +0000
Subject: Bug #74095 [NEW]: Using flush() while php://input is open causes PHP to hang
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207378@lists.php.net to get a copy of this message
From: viskoo at gmail dot com Operating system: Linux PHP version: 7.1.1 Package: Output Control Bug Type: Bug Bug description:Using flush() while php://input is open causes PHP to hang 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 bug report at https://bugs.php.net/bug.php?id=74095&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74095&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74095&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74095&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74095&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74095&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74095&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74095&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74095&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74095&r=support Expected behavior: https://bugs.php.net/fix.php?id=74095&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74095&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74095&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74095&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74095&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74095&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74095&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74095&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74095&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74095&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74095&r=mysqlcfg

« previous php.bugs (#207378) next »