1. PHP Sleep () function
Definition and usage
The sleep () function delays code execution for several seconds.
Grammar Sleep (seconds)
seconds required. The pause time in seconds.
return value
If successful, returns 0, otherwise false.
Error/exception
If the specified description seconds is a negative number, the function generates a e_warning.
Example
<?phpecho date (' H:i:s '). "<br/>"; Pause for 10 seconds of Sleep (10);//start echo date (' h:i:s ') again; >
Output:
12:00:08-12:00:18
2. PHP Usleep () function
Definition and usage
The Usleep () function delays code execution for several microseconds.
Grammar Usleep (microseconds)
microseconds required. Pause time in microseconds.
return value
no return value.
Hints and Notes
Note: This function does not work on Windows systems until PHP 5.
Note: One microsecond equals one out of 10,000 seconds.
Example
<?phpecho date (' H:i:s '). "<br/>";//Delay 10 description Usleep (10000000);//start echo Date again (' h:i:s '); >
Output:
09:23:14-09:23:24
Usage of sleep and unsleep in PHP
When you need a program to pause execution for a few seconds you can use sleep
the int sleep (int $seconds) program pauses $seconds seconds after execution.
Returns Zero on success, or false on error. Returns 0 successfully, error returns false.
If the call is interrupted by a signal, sleep () returns a Non-zero value. On Windows, this value would always be 192 (the value of the Wait_io_completion constant within the Windows API). On other platforms, the return value is the number of seconds left to sleep.
If the call is interrupted by a signal, the function returns a value other than 0. On the Windows platform, this value is always 192 (this value is the constant value of the Windows API waiting for IO to complete wait_io_completion). Other platform return values are the number of seconds that sleep has not yet executed.
If the specified number of seconds is negative, this function would generate a e_warning.
If the parameter is negative, the function produces a warning error.
You can use Usleep when you need the program to suspend execution for 1 seconds.
void Usleep (int $micro _seconds)
Delays program execution for the given number of micro seconds.
The Usleep parameter is microseconds and has no return value.
When you need a program execution unit smaller (less than microseconds) can be used
Time_nanosleep ()-Delay for a number of seconds and nanoseconds
If you want the program to pause execution to a point in time, you can use the
Time_sleep_until ()-Make the script sleep until the specified time