|
Posted by Prathaban Mookiah on 04/10/05 11:23
Thanks Skrol for your reply.
But the problem is, the shutdown function will have to be executed from a lot
of points whenever something goes wrong and I guess calling hello() everywhere
manually is not elegant.
Maybe it should be reported to PHP bugs.
Prathap
---------- Original Message -----------
From: "Skrol 29" <skrol29@freesurf.fr>
To: php-general@lists.php.net
Sent: Sun, 10 Apr 2005 07:27:38 +0200
Subject: [PHP] Re: Problem with ob_get_contents()
> Hi,
>
> 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.
>
> -------------------
> Skrol29
> www.tinybutstrong.com
> -------------------
>
> "Prathaban Mookiah" <prathap@ee.pdn.ac.lk> a écrit dans le message
> de news: 20050409115752.M4371@ee.pdn.ac.lk...
> > Hello,
> >
> > I've posted a miniature version of my code here to explain my problem.
> >
> > <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
> >
> > Thanks in advance for any help.
> >
> > Prathap
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
------- End of Original Message -------
Navigation:
[Reply to this message]
|