开发者

PHP: count down clock

I want to create a timer in PHP that will count down every second. I have some code that works but there's a problem:

for($countdown=20; $countdown >= 0; $countdown--)
{   
    echo "$countdown\n"; //print out the time left
    sleep(1);            //wait one second

    if ($countdown == 0)
    {
        displayscore();
        endgame();
    }
}

The problem with this code is that when the script is sleeping, it can't do anything else, such as track the pla开发者_如何学Pythonyer in the game script I'm writing. How would I go about making a countdown timer in php without using sleep? Perhaps unixtime or clocks units?

Any help would be appreciated

I will elaborate: When someone hits the "finish" in a game I am writing, it calls several functions, and this countdown is one of the functions. Problem is, it can't execute these other functions while it is sleeping.


Instead of actually counting 20 seconds, maybe you can just store the time that the process starts and then compare it to the current time, to tell when 20 seconds has passed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜