Flushing Output to the Browser

You want to force output to be sent to the browser. For example,before doing a
slow database query, you want to give the user a status update.
Solution
Use flush():

print 'Finding identical snowflakes...';
flush();
$sth = $dbh->query('SELECT shape,COUNT(*) AS c FROM snowflakes GROUP BY shape HAVING c > 1');

The flush() function sends all output that PHP has internally buffered to the web
server,but the web server may have internal buffering of its own that delays when
the data reaches the browser. Additionally,some browsers don’t display data immediately
upon receiving it,and some versions of Internet Explorer don’t display a page
until they’ve received at least 256 bytes. To force IE to display content,print blank
spaces at the beginning of the page:

print str_repeat(' ',300);
print 'Finding identical snowflakes...';
flush();
$sth = $dbh->query(
'SELECT shape,COUNT(*) AS c FROM snowflakes GROUP BY shape HAVING c > 1');

See Also documentation on flush()

Tags: , ,

3 Responses to “Flushing Output to the Browser”

  1. Meakid Says:

    When people are saying something, that you don’t like, don’t argue with them, just stop paying attention

  2. 1nfamous Says:

    My only wish is to leave this page and never come back again! Retarded stuff! How could anyone believe it?

  3. Jaanus147 Says:

    No freaking way. I’m absolutely disagreeing. Next time when you post something think about reaction of readers.

Leave a Reply