Reputation: 267049
I have this code:
set_time_limit(0);
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
ob_flush();
flush();
$start = time();
$secs = time() - $start;
while ($secs <= 300)
{
echo "this script has been running for $secs seconds.\n";
ob_flush();
flush();
sleep(1);
}
What I'd like to do when I view this page, is to see in real time how long the script has been running, like this:
Instead what I get is a blank window with a continuous 'loading' sign for 5 minutes, and after 5 mins suddenly i'm bombarded with a load of these messages which i should've been getting 1 message at a time.
Can someone explain what I'm doing wrong?
Upvotes: 4
Views: 647
Reputation: 13709
ob_flush
is not flush
. ob_flush
clears the object buffer that's been opened. Since you don't have an object buffer open, nothing is flushed.
Also, web browsers and web server software are notorious for holding up data until it can be outputted. Make sure GZIPing is turned off and that you're using a sane browser.
Upvotes: 3