PHP Sleep () function
Definitions 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 returns false.
Error/exception
If the specified description seconds is a negative number, the function generates a e_warning.
Example
<?php
echo Date (' H:i:s '). "<br/>"; Pause 10 seconds of sleep
(10);//restart
echo date (' h:i:s ');
? >
Output:
12:00:08 12:00:18
PHP usleep () function
Definitions and usage
The Usleep () function delays code execution for several microseconds.
Grammar Usleep (microseconds)
microseconds required. The pause time in microseconds.
return value
no return value.
Tips and comments
Note: This function cannot work on a Windows system until PHP 5.
Note: One microsecond equals one out of 10,000 seconds.
Example
<?php
echo Date (' H:i:s '). "<br/>";
Delay 10 describes
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 suspend execution for a few seconds you can sleep
the int sleep (int $seconds) program is paused $seconds seconds after execution.
Returns Zero on success, or FALSE on error. Successfully returns 0, error returns false.
If the call is interrupted by a signal, sleep () returns a Non-zero value. On Windows, this value would always be (the value of the Wait_io_completion constant within the Windows API). On the "other platforms", the return value would be 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). The other platform return value is the number of seconds that sleep has not yet been performed.
If the specified of seconds is negative, this function would generate a e_warning.
If the parameter is negative, the function produces a warning error.
When you need a program to suspend execution for 1 seconds, you can use Usleep
void Usleep (int $micro _seconds)
Delays program execution for the given number of micro seconds.
The Usleep parameter is microsecond and has no return value.
When you need a smaller program execution unit (less than microseconds) you can use the
Time_nanosleep ()-Delay for a number of seconds and nanoseconds
If you want the program to suspend execution to a point in time, you can use
Time_sleep_until ()-Make the script sleep until the specified time