|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-04-11 17:53 UTC] sniper@php.net
[2005-04-12 09:58 UTC] vrana@php.net
[2005-04-12 10:08 UTC] vrana@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 22:00:02 2025 UTC |
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