GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Feb-2005, 08:04
firebird's Avatar
firebird firebird is offline
New Member
 
Join Date: Jan 2005
Posts: 11
firebird is on a distinguished road

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  
Old 19-Feb-2005, 11:28
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,435
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by firebird
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?
Don't know, exactly, since I havent read that particular documentation. But generally a flush() command moves the "temporary output" to permanent location.

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.
__________________

Definition: Politics
Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
  #3  
Old 19-Feb-2005, 13:31
firebird's Avatar
firebird firebird is offline
New Member
 
Join Date: Jan 2005
Posts: 11
firebird is on a distinguished road
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  
Old 22-Feb-2005, 21:43
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
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:
<!-- Render banner first --> <table> <tr> <td><a href="/offer.html"><img src="/images/example.gif" /></a></td> </tr> </table> <!-- Start rendering the rest of the page now --> <table> <tr> <td> <p>Some heavy, huge article goes here...</p> </td> </tr> </table>
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:17.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.