Click to See Complete Forum and Search --> : flush()


zombieJones
03-28-2008, 10:11 AM
Is there anything I have to do to make flush() print to the screen the way it supposed to? Server configuration or something?

Like even this simple example I found online doesn't work. Page loads for four seconds and then is printed all at once

<HTML>
<BODY>
This page is loading.<BR />
<?php flush(); sleep(2); ?>
Almost there...<BR />
<?php flush(); sleep(2); ?>
Done.<BR />
</BODY>
</HTML>

stephan.gerlach
03-28-2008, 10:29 AM
Yes you need to have


ob_start();


before you start any output. This will mean that stuff will be stored in the output buffer before sending to the screen.

zombieJones
03-28-2008, 10:59 AM
Thanks for pointing me in the right direction. It wasn't as simple as just adding that line. Apparently flush doesn't work as expected in Linux.

I found this on the php.net ob-implicit-flush page. And it actually works.


This feature happens on Linux versions of PHP...
...There is a workaround using ob_end_flush() and ob_flush, here it is :

<?
// This works !
ob_end_flush();
for($i=0;$i<10;$i++) {
echo "yeah :-))))\n";
@ob_flush();
sleep(1);
}
?>


(now, how do I tag this thread as resolved?)