note 98688 deleted from function.flush by danbrown
| From: | danbrown@php.net | Date: | Wed, 30 Jun 2010 19:08:48 +0000 |
| Subject: | note 98688 deleted from function.flush by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170607@lists.php.net to get a copy of this message | ||
Note Submitter: Rushikumar dot Bhatt at NOSPAM dot uconn dot edu
----
This note is in response to Koalabear's solution
(http://us.php.net/manual/en/function.flush.php#81749)
A simpler and non-messy way is to use the str_repeat function to repeat a space (" ")
_at-least_ 93 times.
As you might expect, start your code with ob_start(); and create a function that repeats the space
string at least 93 times, then call ob_flush() and finally call flush().
(NOTE: It is imperative to note the order... we first call ob_flush() before calling flush())
The following example has been tested with the following browsers and their respective versions:
Internet Explorer v7.0 (v7.0.5730.13)
FireFox v3.6 (v3.6.6)
Opera v10.10 (Build 1893)
Netscape v7.2
Example 1:
-------------
flushTest.php
<?php
ob_start();
/**
*Credit: Koalabear (original)
*/
function hardFlush() {
echo str_repeat(" ", 93);
ob_flush();
flush();
}
?>
<HTML>
<BODY>
This page is loading.<br />
<?php hardFlush(); sleep(2); ?>
Almost there...<br />
<?php hardFlush(); sleep(3); ?>
Done.<br />
</BODY>
</HTML>
HOWEVER, this solution does not work in Google Chrome as expected...
SO, a final solution to this issue, to make it work with all *major* browsers--albeit I would not
put "Netscape" in this category--including Google Chrome, we use str_pad function to pad
an empty input string, having pad length of _at-least_ 2013. (I have yet to find out why 2013 is the
magic number?)
The following example illustrates this.
The following example has been tested with the following browsers and their respective versions:
Internet Explorer v7.0 (v7.0.5730.13)
FireFox v3.6 (v3.6.6)
Opera v10.10 (Build 1893)
Netscape v7.2
Google Chrome v5.0 (v5.0.375.86)
Example 2:
-------------
flushTest.php
<?php
ob_start();
/**
*Credit: Koalabear (original)
*/
function hardFlush() {
echo str_pad("", 2013);
ob_flush();
flush();
}
?>
<HTML>
<BODY>
This page is loading.<br />
<?php hardFlush(); sleep(2); ?>
Almost there...<br />
<?php hardFlush(); sleep(5); ?>
Done.<br />
</BODY>
</HTML>