#32665 [NEW]: Premature flushing of output buffer when register_shutdown function called
| From: | prathap at ee dot pdn dot ac dot lk | Date: | Mon, 11 Apr 2005 06:24:07 +0000 |
| Subject: | #32665 [NEW]: Premature flushing of output buffer when register_shutdown function called | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-76627@lists.php.net to get a copy of this message | ||
From: prathap at ee dot pdn dot ac dot lk
Operating system: Gentoo Linux
PHP version: 5.0.3
PHP Bug Type: Output Control
Bug description: Premature flushing of output buffer when register_shutdown function called
Description:
------------
Hello,
I've posted a miniature version of my code here to explain my doubt.
<CODE>
<?
phpinfo();
ob_start();
register_shutdown_function("hello");
echo ("HELLO");
die();
function hello()
{
$logfile = "logfile";
$error_string = ob_get_contents();
if(!$handle = fopen($logfile, "a"))
{
echo("Could not open logfile for writing!");
ob_end_flush();
exit;
}
if(fwrite($handle, $error_string) === FALSE)
{
echo("Could not write to logfile!");
ob_end_flush();
exit;
}
fclose($handle);
ob_end_clean();
}
?>
</CODE>
This simply does not work the way it should. i.e ob_get_contents doen't
return
any string and the buffer just gets flushed by itself at termination.
Though the PHP manual says it is not possible to retrieve the contents of
any
output buffers using ob_get_contents() with PHP < 4.0.6. But I am using
PHP 5.
x.x
I posted this problem in the mailing list and I got this response from
skrol29:
I've tested your code on PHP 4.3.3 and I have the same behavior has yours.
"Hello" is output at the end of the PhpInfo data, followed by a PHP notice
:
Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in
...
And there is an empty "logfile" file created in the Apache directory
insteaf
of the script's directory.
If you change in your script:
***********
register_shutdown_function("hello");
echo ("HELLO <br>");
die();
***********
by
***********
// register_shutdown_function("hello");
echo ("HELLO <br>");
hello()
die();
***********
then it runs as expected and the "logfile" file is created in the script's
directory.
It seems that when calling the shutdown function, all the buffered output
is
immedialty sent to the client and the buffer mode is closed.
You maybe have PHP bug here, or the manual is wrong about the possibility
to
retrieve the contents.
But we can notice that this also happens at the end of a script when there
is no shutdown function.
----
I am still not sure if this is a bug. But I would be very grateful if
someone generously volunteers to see to this.
Thank you and congrats on for the good work you have been carrying on all
throughout.
Prathap
--
Edit bug report at http://bugs.php.net/?id=32665&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32665&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32665&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32665&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32665&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32665&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32665&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32665&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32665&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32665&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32665&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32665&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32665&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32665&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32665&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32665&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32665&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32665&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32665&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32665&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32665&r=mysqlcfg