Output buffering

Describe how to use output buffering for:

  • Chat
  • Server information
  • Progress information on longer tasks - such as picture thumbnailing.

clock-example.php

<?php
    set_time_limit
(0); // we don't want script to expire

    // Tell parser to stop buffering and flush on our command
    
ob_end_flush();

    
// Keep running till user stops us
    
while (1) {
        
// Print clock
        
print date("j/n - Y - G:i:s")."<br>\n";

        
// Send our current buffer to the user
        
flush();

        
// Wait one second before continuing
        
sleep(1);
    }
?>
See script in action >>