PHP sleep() excution sequence while echoeing.

Posted by Babiker on Stack Overflow See other posts from Stack Overflow or by Babiker
Published on 2010-06-03T05:08:12Z Indexed on 2010/06/03 5:14 UTC
Read the original article Hit count: 205

Filed under:

I have the following:

echo time()."<br>";

sleep(1);
echo time()."<br>";

sleep(1);
echo time()."<br>";

I wrote the preceding code with intention to echo time()."<br>" ln 1,echo time()."<br>" ln 4, wait a final second and then echo the final time()."<br>". Altough the time bieng echoed is correct when it comes to the intervals between time(), all echo functions are echoeing after the total of the waiting period/parameters in each sleep function.

This is how the script runs:

  • Excutes.
  • Waits 2 secons.
  • echoes
    1275540664
    1275540665
    1275540666

Notice the correct incrementation in time() being echoed. My question is why is it not behaving like expected to where it echoes, waits a second, echoes again, waits one final second and then echos the last parameter?

I know my question is a little confusing due to my wording, but i will try my hardest to answer any comments regarding this, thanks.

© Stack Overflow or respective owner

Related posts about php