Progressive page updates
Now this is cool: The joy of flush() shows how PHP’s flush() function can be used to send data to the browser before a page has finished rendering. Check out Ben’s demo page to see the trick in action.
I’ve seen this in use on a few sites for progress indicators, but I’d never realised how easy it was to achieve in PHP. The progress indicator trick is pretty neat—it generally works by having a progress indicator widget that can be modified by javascript, then flushing a <script> element with a call to the progress incrementing function whenever an operation in the server side code has been completed. I’ve seen it used for IRC style chat applications as well, but I’ve always been concerned about the server resources that must be tied up in serving multiple persistent connections at once.
Pepino - 23rd October 2003 16:52 - #
This is a useful technique! One thing to keep in mind (excerpted from the PHP manual entry on
flush()):This is useful to know -- with a quick test, this output buffering limitation seems to be true for IE6. Easy enough to get around:
<?=(str_repeat(' ',256)."\n")?>can go somewhere between (X)HTML tags in the top of the document.
Nathan - 23rd October 2003 18:11 - #
Scrivs - 23rd October 2003 18:49 - #
I've used similar stuff on www.sj-web.com, using ASP's Response.Flush to send completed blocks of text to the browser.
Very usefull, because that site has a lot of database queries and this gives the user impression that something is happening while data is gathered and processed.
Also, browser tend to mess up the design if they receive part of the block, like half the table or just part of stylized list, so one must be carefull when to flush things.
Also, Internet Explorer and Opera allow you to do document.write in the header - can be usefull when you want to write messages to user while page is loading. I used this on the same site - at first it had messages like "loading betslip engine", "loading styles" etc, but client wanted to jsut say "loading, please wait". Oh well, tie the horse where the Lord says.
aleck - 24th October 2003 01:10 - #
ASP has similar functionality through the Flush method of the Response object. By default, latter versions of ASP buffer the output, but the Flush method can be used to control how data is sent to the client. These functions are really useful when doing intensive database queries, as they assure the visitor that something is happening as the page slowly loads.
Gez Lemon - 24th October 2003 06:19 - #
Rich - 24th October 2003 10:04 - #
Paul Baxter - 24th October 2003 15:01 - #