I'd like to create a for() or while() loop, but write in a pause of 'x' number of seconds to each iteration of the loop. I've been tying to use sleep() with no luck. Does anyone have any suggestions?

Thanks 🙂

    sleep() is definitely working, how did you use it?

      for($i=1; $i <= 10; $i++)
      {
      echo($i);
      sleep(2);
      }

      ...sure, it waited the 2 seconds, but it blurted out the results at the end, instead of iterating every 2 seconds.

        use flush():

        for($i=1; $i <= 10; $i++) 
        { 
        echo($i); 
        flush();
        sleep(2); 
        }

          I see the sense in using flush(), but after reading about it in http://www.php.net/manual/en/function.flush.php, I'd bet a dollar (or D-mark) that its my win2k/xitami platform thats buffering the output till the script is finished. I'll have to do some research to be sure.
          If thats the case, does it mean that the loop itself isn't iterating untill the very end, or does it simply mean that the data isn't being displayed untill the end. When all is said and done, the data won't be displayed anyway. As long as the loop is doing its job, all is well.

            some browsers need a certain amount of chars until they first
            flush the output
            insert some useless html-tags at the beginning (several lines)
            and run again

              Yep, thats it.
              So, at least I know this function is doing its job.
              Thank you so much for being a sounding board 🙂

                Write a Reply...