Flush the Buffer Early - speed tip
Posted: Sat Aug 02, 2008 9:34 pm
A users request a page, which can take anywhere from 200 to 500ms for the backend server to stitch the HTML page. The browser is idle during this time, waiting for the data. PHP has the function flush(). Yea of us
function flush allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefit is mainly seen on busy backends or light frontends.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
...
...
Now for us all we have to do is make a UDT, lets say {flush}, containing,
You could put this any where you want to but this is the best IMHO place to do it...
{flush}
As always, use at your on risk, though it should cause no harm, it's your site and your responsibility.
jeremyBass

A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
...
...
Now for us all we have to do is make a UDT, lets say {flush}, containing,
Code: Select all
//needed air to present this
//
?><?php flush();
//
//
You could put this any where you want to but this is the best IMHO place to do it...
{flush}
As always, use at your on risk, though it should cause no harm, it's your site and your responsibility.
jeremyBass