PHP Function Time_Sleep_Until
There are various times when your content script might need to pause for an interval. It could be a simple way to stop your content from flooding the network or consuming excessive CPU resources. The inbuilt PHP functions sleep() and usleep() halt the execution of the current program for a predefined number of seconds and microseconds respectively.
These are just two of the many time-related php functions that are available in the PHP library. Another great one is the microtime() function which gives you the ability to get a precise timestamp with millisecond precision. This is useful when you need to time your frame production and ensure that each frame is produced within a certain amount of time.
Both the sleep() and usleep() functions accept an integer parameter that is used to determine how long the current program will pause for. The function will not return until the specified time has passed. However, there are some issues associated with these two functions which is mainly due to the fact that they consume more CPU cycles compared to other PHP time-related functions.
These functions can be replaced with the php function time_sleep_until that was introduced in the latest version of PHP. This function will pause the program execution for the given number of seconds and microseconds and will return TRUE on success or FALSE if interrupted. The value of this time delay will vary depending on the platform.