Is there a function similar to setTimeout() (JavaScript) for PHP?

前端 未结 9 1524
离开以前
离开以前 2020-12-06 16:08

The question sort of says it all - is there a function which does the same as the JavaScript function setTimeout() for PHP? I\'ve searched

相关标签:
9条回答
  • 2020-12-06 16:59

    PHP isn't event driven, so a setTimeout doesn't make much sense. You can certainly mimic it and in fact, someone has written a Timer class you could use. But I would be careful before you start programming in this way on the server side in PHP.

    0 讨论(0)
  • 2020-12-06 17:00

    http://php.net/manual/en/class.evtimer.php is probably what you are looking for, you can have a function called during set intervals, similar to setInterval in javascript. it is a pecl extension, if you have whm/cpanel you can easily install it through the pecl software/extension installer page.

    i hadn't noticed this question is from 2010 and the evtimer class started to be coded in 2012-2013. so as an update to an old question, there is now a class that can do this similar to javascripts settimeout/setinterval.

    0 讨论(0)
  • 2020-12-06 17:02

    There's the sleep function, which pauses the script for a determined amount of time.

    See also usleep, time_nanosleep and time_sleep_until.

    0 讨论(0)
提交回复
热议问题