|
-
Dec 11th, 2007, 06:13 AM
#1
Thread Starter
Hyperactive Member
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);
}
?>
-
Dec 11th, 2007, 11:04 PM
#2
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.
-
Dec 12th, 2007, 01:49 AM
#3
Thread Starter
Hyperactive Member
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);
}
?>
-
Dec 12th, 2007, 02:18 AM
#4
Thread Starter
Hyperactive Member
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);
}
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|