Applying PHP Flush To Give The Illusion of Faster Loading Web Page For PHP Websites

Website owners who are powering their websites with PHP (a programming language) can use PHP Flush to either inform visitors that the website is loading or giving the illusion of a faster loading website.  PHP Flush is a tactic in which PHP attempts to push data out to the browsers at the call of PHP Flush.  Portions of heavy script callings from parts of websites can utilize PHP Flush in facilitating the display of contents.  Instead of making website visitors to wait for all the contents of a website assemble and then push out, PHP Flush can just push out parts of website’s contents immediately, giving the illusion of a faster loading website.  With that trick, PHP Flush can also use in combination with other PHP codes to display a pleading message which begs website visitors to wait as contents are loading — making a website a tad more interactive, albeit one way interaction.

So how do we use PHP Flush?  Just type in the code that looks similar to the examples in the images:

Taking straight from Yahoo’s Best Practices for Speeding Up Your Website, I’m quoting this to let you know why PHP Flush is best to be between the end tag of header and beginning tag of body:

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.

In the second image, as you see I’m using “sleep” function to pause PHP from spitting out all contents just to show you that PHP Flush is working as it’s spitting out fragments of a whole web page.  To make the matter even more clear, why don’t you try to use the same exact code but take out the PHP Flush?  Without PHP Flush and with only “sleep” function which to pause PHP, nothing within the buffer will get flush out right away and so the result is obvious that you have to wait for everything to be buffered before any content gets display.

PHP Flush does not always work the same way for all browsers.  In IE, I don’t know if this is still the case, but from reading around, it seems that IE will not allow PHP Flush to do its job if PHP Flush calls in a spot within the web page that does not yet render more than or equal to 256 bytes.  PHP Flush cannot override the buffering scheme of Apache and other web server software.  PHP Flush cannot override the buffering scheme of browsers.

Nonetheless, PHP Flush helps flushing out the data within the buffer immediately when it does work, and the result is gorgeous — the illusion of faster loading website.  Why I think it’s an illusion?  When looking at a complete picture, one does see that for a heavy web page that is using PHP Flush, the complete loading of such a web page cannot be finished until everything get flush completely from the buffers.  Therefore, PHP Flush solves the problem where website visitors stare at a blank loading web page, but it cannot solve the problem completely such as really speeding up the loading of a web page.  To really speeding up a loading of a website in whole, one must applies all techniques from best practice cases involving with server side optimization and client side optimization through codes and hardware.


About these ads

Get every new post delivered to your Inbox.

Join 784 other followers