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

From: Date: Tue, 14 Feb 2017 14:21:59 +0000
Subject: Bug #74095 [Opn]: Using flush() while php://input is open causes PHP to hang
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207379@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74095&edit=1 ID: 74095 User updated by: viskoo at gmail dot com Reported by: viskoo at gmail dot com Summary: Using flush() while php://input is open causes PHP to hang Status: Open Type: Bug Package: Output Control Operating System: Linux PHP Version: 7.1.1 Block user comment: N Private report: N New Comment: Forgot to include the command to test: curl -XPUT --data-binary @some_large_file.txt http://localhost:1234/ Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#207379) next »