-
sleep()
Hi,
I have a situation, I found problem regarding sleep(). I like to display seconds from 60 to 0. First it will display 60, then after sleep() of 1 second it will display 59 and so on until it reach to 0. But it will display the all 60 numbers at a time, whereas I like to display one number at a time with 1 second interval.
Here is my code. Please help. Thanks a lot.
PHP Code:
<?php
for($i=60;$i>=0;$i--)
{
echo $i;
sleep(1);
}
?>
-
Re: sleep()
Call ob_flush before calling sleep. This will flush the response stream and ensure the latest number is displayed on the client side.
Edit: make that @ob_flush() to suppress a notice if output buffering happens to be disabled.
-
Re: sleep()
Thanks for reply penagate. But this does not make any difference. Following is my rectified code. Please help. Thanks a lot.
PHP Code:
<?php
for($i=60;$i>=0;$i--)
{
echo $i;
ob_flush();
sleep(1);
}
?>
-
Re: sleep()
I use flush() instead of ob_flush() and this is working. But I would like see the number in decreasing order one at a time. But here numbers are displayed like this 60595857..... Please check it out. Thanks a lot.
PHP Code:
<?php
for($i=60;$i>=0;$i--)
{
echo $i;
flush();
sleep(1);
}
?>