Bug #67381 [Asn]: Output buffers stop working after client disconnect

From: Date: Wed, 19 Nov 2014 09:06:26 +0000
Subject: Bug #67381 [Asn]: Output buffers stop working after client disconnect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188671@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67381&edit=1 ID: 67381 Updated by: mike@php.net Reported by: phpbugs at musiclogistics dot net Summary: Output buffers stop working after client disconnect Status: Assigned Type: Bug Package: Output Control Operating System: all PHP Version: Irrelevant Assigned To: mike Block user comment: N Private report: N New Comment: Related to Bug #64152 Previous Comments: ------------------------------------------------------------------------ [2014-11-19 08:42:24] mike@php.net This could be a regression introduced in PHP-5.4 with the new output API. Hard to say, though, because the previous code is such a mess. ------------------------------------------------------------------------ [2014-06-27 16:16:53] phpbugs at musiclogistics dot net Sorry, the delivery of the extended test script was blocked by our server config. This is now fixed. ------------------------------------------------------------------------ [2014-06-04 13:27:22] phpbugs at musiclogistics dot net Description: ------------ Capturing output as a string with an output buffer stops working as soon as PHP has detected a client disconnect. The buffer is always empty, regardless of whether something was "echoed" into it. Verified with different PHP 5.4 and 5.5 builds on Linux and Win7 with Apache 2.2, Apache 2.4 and PHP-FPM SAPIs. While this behaviour may be intentional (although not documented to my knowledge), it may break common use cases. Writing into an output buffer and then grabbing the contents is what e.g. the popular template engine Twig does when rendering a template. A common case when this might happen after client disconnect is when Twig is used to render the body of an e-mail at the end of a long-running request. A more comprehensive test script which also demonstrates a related GD bug can be found here: http://www.musiclogistics.net/phpbugs/write_to_ob_after_disconnect.phps Test script: --------------- // Prevent script from exiting when client disconnects ignore_user_abort(true); // Flush & close all output buffers to make the echo/flush calls // below send data to the client immediately while (ob_get_level()) { ob_end_flush(); } // Wait until client has closed connection while (!connection_aborted()) { echo "Abort the request in your browser now by pressing <Esc> or clicking the little X in the adress bar...\n"; flush(); sleep(1); } ob_start(); echo 'Hello World'; $captured_output = ob_get_clean(); file_put_contents(__DIR__ . '/ob-bug-test.log', strlen($captured_output)); Expected result: ---------------- 11 (in the log file 'ob-bug-test.log') Actual result: -------------- 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67381&edit=1

« previous php.bugs (#188671) next »