|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67381 Output buffers stop working after client disconnect
Submitted: 2014-06-04 13:27 UTC Modified: 2015-04-13 15:06 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phpbugs at musiclogistics dot net Assigned: mike (profile)
Status: Closed Package: Output Control
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: phpbugs at musiclogistics dot net
New email:
PHP Version: OS:


 [2014-06-04 13:27 UTC] phpbugs at musiclogistics dot net
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:

Test script:
// Prevent script from exiting when client disconnects

// 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";

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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-27 16:16 UTC] 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-30 13:09 UTC]
-Assigned To: +Assigned To: mike
 [2014-11-19 08:42 UTC]
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-11-19 09:06 UTC]
Related to Bug #64152
 [2015-04-13 15:06 UTC]
-Status: Assigned +Status: Closed
 [2015-04-13 15:06 UTC]
Behavior fixed in PHP-7. See
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 20:01:29 2023 UTC