sleep() output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrsjrs
    New Member
    • Sep 2006
    • 24

    sleep() output

    <?php
    echo "<BR><BR>A) Present time is:<BR>";
    echo date('h:i:s') . "\n<BR>Dela ying 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?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Take a look at he flush() and ob_flush() functions.

    Comment

    • jrsjrs
      New Member
      • Sep 2006
      • 24

      #3
      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.

      Comment

      Working...