The php Function Ob_End_Clean
The php function ob_end_clean removes the contents of an output buffer in php. This allows developers to create optimized web pages as it can prevent unnecessary output from occurring on the page.
By default, echo and other similar functions in php are sent immediately to the browser without any buffering. To improve performance and make things work more efficiently it is advisable to use PHP’s built in output buffering functions that gather the results of echo and other commands into a buffer and send them later, or discard them altogether.
Output buffering is activated by calling ob_start() with PHP_OUTPUT_HANDLER_FLUSHABLE and PHP_OUTPUT_HANDLER_REMOVABLE flags. Once active it can be removed by calling ob_end_flush() or ob_end_clean(). Both functions perform the same task but the difference is that ob_end_flush() also sends the buffer contents to the browser while ob_end_clean() saves the buffer contents in a variable before emptying it.
Buffering is a very useful feature that helps reduce the time it takes for a page to be generated by a server as the HTML can be processed in the background while other components of a webpage are fetching from the browser. However it is important to know when and how to stop the buffering as it may cause problems with dynamically generated content or images in a web page.
By setting a directive in a configuration file that affects all PHP scripts it is possible to disable PHP’s output buffering, but enabling it on a need basis may be preferable. Using PHP’s built in functions like ob_get_contents(), ob_end_flush() and ob_end_clean() is the best way to do this.