Using the PHP Function ob_get_flush() to Start Output Buffering
PHP output buffering allows developers to avoid re-writing and re-executing the same code on each page request by keeping a copy of the last output sent to the browser in a special internal buffer. This can greatly reduce the amount of time it takes for a web page to load and display on the user's computer. Buffering is also useful for avoiding a 504 Gateway Time-out error which can occur when Apache/NGinx is not configured to handle output buffering.
To start output buffering in a script, call the ob_start() function. This will begin storing all output to the internal buffer. Output echoed or printed prior to the ob_start() call will not be stored in the buffer, but instead immediately send to the browser or terminal.
Once the buffer is full, it will be flushed out. The contents of the buffer will be sent to the browser or terminal as a single string.
As an optional parameter, ob_start() accepts a callback function that can be used with the buffering system to perform custom output processing. This can include generating a markup language (like PDML or XHTML), performing customized content rewriting (e.g. URL rewriting, output escaping), or even implementing a custom templating engine.
Another useful callback function is ob_gzhandler() which can be used with the ob_start() system to gzip compress all output sent to the browser. This can help reduce the bandwidth required to deliver a page, and also reduce the time it takes for the browser to download compressed data.