simple ob_start(), flush(), ob_gzhandler, sleep(), HEREDOC examples

//ob_start()
ob_start();
print “Hello First!\n”;
ob_end_flush();

ob_start();
print “Hello Second!\n”;
ob_end_clean();

ob_start();
print “Hello Third!\n”;

//outputs “Hello First! Hello Third!”

//flush()

<HTML>
<BODY>
<DIV ID=”flushme”>
Hello, world!
</DIV>
< ? php flush(); sleep(2); ? >
<SCRIPT>
d = document.getElementById(“flushme”);
d.innerHTML = “Goodbye, Perl!”;
</SCRIPT>
< ? php flush(); sleep(2); ? >
<SCRIPT>
d.innerHTML = “Goodnight, New York!”;
</SCRIPT>
</BODY>
</HTML>

// compressed output

< ? php
ob_start(‘ob_gzhandler’);
print “My content\n”;
ob_end_flush();
? >

// sleep

< ? php
ob_implicit_flush(true);
for($i=0;$i<5;$i++)
{
$dis=<<<DIS
<div style=”width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;”>
$i
</div>
DIS;
echo $dis;

sleep(5);
//flush();
}
? >

Comments are closed.