Page 1 of 1

Flushing HTML to browser while looping

Posted: Fri Feb 10, 2006 4:30 pm
by Jeroen Oosterlaar
Hi,

I have a problem regarding flushing the output buffer to the browser while walking through a for-loop. I want to show a progress bar while my mailing list sending routine is executing. To keep things simple see the following simplified snippet:

Code: Select all

for($i = 0; $i < count($addresses); $i++)
{
    mail(...);
    echo ".";
    ob_flush();
    flush();
    sleep(1);
}
The strange thing is: when running the script (which, on average, takes about 1 minute), the output seems to be flushed when viewing the source code of the page during the execution, but the output is not being rendered to the screen by the browser.

What could be the problem and is there a solution?

Thanks in advance!

Posted: Fri Feb 10, 2006 4:45 pm
by feyd
it's your browser's choice to render or not. Since it knows the page isn't done loading, nor did an element finish, it will likely choose to not draw anything, as it can't calculate the dimensional requirements.

Posted: Fri Feb 10, 2006 9:52 pm
by Ambush Commander
Firefox has an about:config option nglayout.initialpaint.delay, which "determines time in milliseconds to wait before an initial reflow attempt during page rendering." and set it to 0, it should speed rendering.