Bug #67381 [NEW]: Output buffers stop working after client disconnect
From: phpbugs at musiclogistics dot net
Operating system: all
PHP version: Irrelevant
Package: Output Control
Bug Type: Bug
Bug description:Output buffers stop working after client disconnect
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 bug report at https://bugs.php.net/bug.php?id=67381&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67381&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67381&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67381&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67381&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67381&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67381&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67381&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67381&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67381&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67381&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67381&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67381&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67381&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67381&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67381&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67381&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67381&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67381&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67381&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67381&r=mysqlcfg
Thread (5 messages)
- phpbugs at musiclogistics dot net