php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30015 output buffer closed before shutdown functions called
Submitted: 2004-09-07 22:17 UTC Modified: 2012-04-14 12:18 UTC
From: php at terrarium dot f9 dot co dot uk Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.8 OS: Debian GNU/Linux Unstable
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at terrarium dot f9 dot co dot uk
New email:
PHP Version: OS:

 

 [2004-09-07 22:17 UTC] php at terrarium dot f9 dot co dot uk
Description:
------------
When using output buffering if the output buffer is still 
open when the script terminates php automatically closes 
it and writes the contents to the browser. 
Unfortunately it does this before any functions which have 
been registered with register_shutdown_function are 
called, so these functions cannot manipulate or cancel the 
output. 
It also prevents shutdown_functions adding headers. 
 

Reproduce code:
---------------
<?php

ob_start();
register_shutdown_function( 'clear_buffer' );

function clear_buffer() {
  ob_end_clean();
}

echo 'Foo';


?>

Expected result:
----------------
No output displayed as the output buffer is cleared at the 
end of the script 

Actual result:
--------------
Foo is output 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-08 00:21 UTC] rasmus@php.net
This is not a bug as it works exactly as designed.  Shutdown functions run on an aborted or timed out connection as well.  As such, they are designed to be run after the connection has been terminated and all output has been sent.
So at most this is a feature request to have some other level of clean up function added.
 [2004-09-08 16:01 UTC] php at terrarium dot f9 dot co dot uk
While I agree this is certainly the case in versions of  
php < 4.1 the manual states:  
  
"Since PHP 4.1, the shutdown functions are called as the  
part of the request so that it's possible to send the  
output from them. There is currently no way to process the  
data after the request has been completed. "  
  
Perhaps it is the documentation that needs clarifying but  
it certainly gives the impression that with php >= 4.1  
these functions are a valid place to manipulate the script  
output.
 [2012-04-14 12:18 UTC] nikic@php.net
Closing as this was already fixed in the meantime.
 [2012-04-14 12:18 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 15 14:00:03 2025 UTC