Using the PHP Function Ob_Clear to Control Output Buffering
PHP may not be as hip or cool as JavaScript, but it still powers 25% of the web and is here to stay. It also has some neat functions for controlling output buffering that give you a lot of control over what is emitted to your browser.
Using these functions can help you get around issues with PHP’s output buffering that are caused by things like antivirus software or other web browser add-ons that hold data until the whole page is loaded. By enabling these controls on a per-script basis, you can avoid the problems and allow the browser to get the data quickly.
One of the nice functions for controlling ob_flush and other output buffering mechanisms is the ob_clean function. This function empties (hence the name) the current topmost output buffer and then closes it. It also deletes the contents of this buffer, so it’s not really a good idea to call this while an active output buffer is in use.
This function is used with ob_start(), ob_get_contents() and ob_end_flush(). The ob_start() function turns on output buffering at a specific level (currently 0). The ob_get_contents() function grabs all the data accumulated since the ob_start() call, and usually assigns it to a variable. The ob_end_flush() function sends all of this data to the browser and clears out the output buffer. The ob_clean() function discards the contents of this buffer and then turns off output buffering.