![]() |
|
#1
|
||||
|
||||
flush() / ob_flush() - what for?I've read the documentation @php.net, however it hasn't cleared my mind.
What exactly happens when you use flush() or ob_flush()? Why would you ever want to use these, theorically, and practically? |
||||
|
#2
|
||||
|
||||
|
Quote:
What this really means is: When you output a value to disk (for example), the output doesn't reach the disk immediately. It is held in a buffer until 1) the buffer is full 2) the program exits 3) the buffer is flushed at which point the disk actually receives the data. The reason for this is it's expensive (time- and resource-wise) to output each and every write immediately. It's cheaper to 'buffer' the output and write larger blocks. This is faster and uses fewer resources because the disk I/O is tweaked (optimized) to perform better when writing blocksof data of specific sizes. Sometimes though, the programmer deems it necessary to output more often than the system is designed for, usually to prevent loss of data in the event of a crash, or the data must be written now because another program needs it immediately. That's what the flush() commands are for -- to output that internal buffer on demand. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#3
|
||||
|
||||
|
Thanks for the explanation! If I may be so free;
does everything get buffered? i.e. using "echo $i", will it buffer $i, and output it after the whole program has finished in your browser? What about this; sometimes you'll get to a page on the net (.php) which says 'loading, please wait', ander after a while something will appear under it (perhaps the result of a search). Would that be done by outputting, printing, 'loading, please wait', thereafter flushing the buffer, and follow it with code that actually takes care of your asked process (seek etc)? Cheers! |
|
#4
|
||||
|
||||
|
Very good question firebird. One I asked myself many times before in the past. I am not from the IT line so sometimes the jargon can be a bit daunting and overly complicated but WaltP's explanation is good enough for anyone to understand the concept.
About your third paragraph. Unless the webmaster has some JavaScript/Flash in place to handle such things, I think it's just a matter of clever use of hypertext markup. For example, if you had a page laid out with single, large table holding all the content within that page, even flushing your buffer before the end of the page will not render the page the way you'd expect it to on your browser. So your browser also comes into play. Let's say, you have designed a web page with content that can be considered heavy. You just happen to place it all inside a <table>. Let's also assume you want a banner to appear at the top of the web page so it's displayed way ahead or while the rest of your content is loading, here's one crude example how you may achieve that. HTML Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The