php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20447 Register_shutdown_function - connection still open while registered shutdown...
Submitted: 2002-11-15 10:32 UTC Modified: 2004-08-27 11:02 UTC
Votes:32
Avg. Score:4.6 ± 0.9
Reproduced:30 of 30 (100.0%)
Same Version:7 (23.3%)
Same OS:10 (33.3%)
From: richardz at omniture dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.3 OS: RedHat 7.2
Private report: No CVE-ID:
 [2002-11-15 10:32 UTC] richardz at omniture dot com
My problem is that the connection to the browser is still open while the registered shutdown functions are executing.  The documentation says that from the registered shutdown functions you WON'T be able to echo or print or modify the contents of the buffer. I can...

Example:
using apache 1.3.27
php version 4.2.3
//////////////////////////////////////////////
<?
function doThing(){
     for($i=0;$i<100000;$i++){
          //just looping to demonstrate that the page hangs while executing this function
     }
     echo "PHP documentation says I shouldn't see this in my browser";
}
register_shutdown_function('doThing');

?>
<html>
Test Page.
<br><br>
</html>
////////////////////////////////////////////


I was hoping to register shutdown functions to do some cleanup - without affecting the load time of the site.  Apparently these functions don't work that way?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-16 12:14 UTC] firewire at itsyourdomain dot com
I to have run across this problem. I was hoping to use a registered shutdown function to do some final fairly slow socket processing that the client didn't need to see. My test case is as follows:

register_shutdown_function('sd');

function sd()
{
  echo "I shouldn't be seen";
  sleep(5);
}

Causes the browser to echo text then sleep for 5 seconds before completing the page. I also agree that the manual is incorrect. Is there another way to force php to close the output stream so slower non user related functions can be executed?
 [2003-05-04 02:31 UTC] spic@php.net
Is this a documentation problem or a php-bug?

According to some users the documented behaviour worked under PHP < 4.1.0, but now the function behaves differently.

Could someone please check this?
 [2003-08-10 21:24 UTC] iliaa@php.net
This is a documtation problem.

Under certain condition you may infact be able to output data to the browser from inside the register_shutdown_function handler.
 [2003-11-20 17:09 UTC] gabe at websaviour dot com
Could you elaborate on that please?  I am experiencing 
the bug in PHP 4.3.0 and Apache 1.3.27 on OS X, 10.2.8, 
as well as PHP 4.1.2 on Apache 1.3.22 on Red Hat Linux.

Under what conditions will it work?  I need this 
function to work as advertised to perform some time-
consuming tasks in the background and let the user move 
on.  Since this is pretty much the only way to achieve 
anything approaching asynchronous processing in the 
Apache PHP environment it seems fairly important.
 [2004-03-18 04:02 UTC] php at mcking dot nl
I tested this on a system with:
OS: Fedora Linux Core 1
Apache version: 2.0.48-1.2
PHP version: 4.3.4-1.1

And the connection to the browser was still open. So the bug isn't solved yet!
 [2004-06-25 14:33 UTC] mail at spybreak dot de
I'm really interested myself under which conditions a script still can output data to the client using register_shutdown_function(). If this is a documentation problem, how's this really supposed to work?
 [2004-06-25 14:33 UTC] mail at spybreak dot de
I'm really interested myself under which conditions a script still can output data to the client using register_shutdown_function(). If this is a documentation problem, how's this really to work?
 [2004-08-26 05:47 UTC] lox at gecka dot com
I will be nice to repair this function guys. 
The behavior descibed in the documentation is the one we need.
 [2004-08-26 11:54 UTC] vrana@php.net
register_shutdown_function() will not probably change back so I filled feature request for such a function: http://bugs.php.net/bug.php?id=29846

Conditions for when output can be written from register_shutdown_function() still have to be documented.
 [2004-08-27 11:02 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"In PHP 4.0.6 and earlier under Apache, the registered shutdown functions are called after the request has been completed. 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."
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 20:01:57 2014 UTC