By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

sleep() output

P: 24
<?php
echo "<BR><BR>A) Present time is:<BR>";
echo date('h:i:s') . "\n<BR>Delaying 5 seconds, new time is:<BR>";
sleep(5);
echo date('h:i:s') . "\n<BR>";
?>

This first script delays 5 seconds then prints everything.
How can we make it immediately print the present time,
tell us that there is a delay,and then print
the concluding delayed time after 5 seconds?

<?
echo "<BR><BR>B) Count the numbers to 6:<BR>";
for($k=1 ; $k<=6 ; $k++){
echo("$k<br />");
sleep(3);
}
?>

Similarly, this second script has a long delay
and then writes all the numbers at once.
How can we make it write the numbers one at a time
with a 3 second delay between them?
Feb 4 '07 #1
Share this Question
Share on Google+
2 Replies


Motoma
Expert 2.5K+
P: 3,235
Take a look at he flush() and ob_flush() functions.
Feb 4 '07 #2

P: 24
Thanks Motoma.
I am finding that these ob commands are really temperamental.
However my scripts work ok most of the time.
So I am now trying to do the same in javascript using setTimeout().
But this has some quirks of its own too!
Wish me happy slogging. Thanks again.
Feb 7 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.