Web lists-archives.com

Re: [PHP] ob_start() -- ob_end_flush() problem




On Thu, Apr 27, 2017 at 8:00 AM, Tedd Sperling <tedd@xxxxxxxxxxxx> wrote:

> Here’s the situation — I use ob_start() --  ob_end_flush() (see below) and
> my code works.


> However, when my students try it, even using my code, it doesn’t work for
> them.
>

How does it fail? Do they get double output? No output? Fatal error? Car
explodes? You're really not giving us much to go on here. :)

It looks like you're missing some important comments and--though it's early
and I may be a little groggy still--the function of ob_end_flush().

    /* start buffered output */
>     ob_start();



    /* capture buffered output */

    $page = ob_get_contents();
>
>     /* buffer captured buffered output */
>     echo($page);
>
>     /* send buffered output and stop buffering */
>     ob_end_flush();


Calling ob_get_contents() returns the current buffer *without clearing its
contents*. You then output that right back into the buffer. Finally,
calling ob_end_flush() outputs the current buffer and stops (that level of)
buffering.

My guess is that "it doesn't work" means that the image is corrupted
because it's doubled in the response and you're using a browser that
handles that kind of image corruption.

Cheers!
David