Flushes the output buffers of PHP and whatever backend PHP is using (CGI, a web server, etc). This effectively tries to push all the output so far to the user's browser.
example1:
<?
if (ob_get_level() == 0) ob_start();
loop{
tables and stuff
echo str_pad("
\n",8);
}
ob_flush();
flush(); // needed ob_flush
usleep(50000);// delay minimum of .05 seconds to allow ie to flush to screen
?>
example2:
<?php
header('Content-type: multipart/x-mixed-replace;boundary=endofsection');
print "\n--endofsection\n";
$pmt = array("-", "\\", "|", "/" );
for( $i = 0; $i <10; $i ++ ){
sleep(1);
print "Content-type: text/plain\n\n";
print "Part $i\t".$pmt[$i % 4];
print "--endofsection\n";
ob_flush();
flush();
}
print "Content-type: text/plain\n\n";
print "The end\n";
print "--endofsection--\n";
?>
Server Push with "multipart/x-mixed-replace", tested on Firefox 2.0.0.11
This is an example requiring both ob_flush and flush.
Monday, December 17, 2007
Flush The Output Buffer
POSTED BY
Oriol
AT
5:56 AM