This article mainly introduces the PHPsleep () function and usleep () function. if you need it, refer to the PHP sleep () function.
Definition and usage
The sleep () function delays code execution for several seconds.
Syntax sleep (seconds)
Seconds required. The pause time in seconds.
Return value
If the call succeeds, 0 is returned. otherwise, false is returned.
Error/exception
If the specified description seconds is a negative number, this function generates an E_WARNING.
Example
"; // Pause for 10 seconds sleep (10); // restart echo date ('H: I: s');?>
Output:
12:00:08 12:00:18
PHP usleep () function
Definition and usage
The usleep () function delays code execution in several microseconds.
Syntax: usleep (microseconds)
Microseconds is required. The pause time in microseconds.
Return value
No return value.
Tips and comments
Note: Before PHP 5, this function cannot work on Windows.
Note: one microsecond equals to one second per million.
Example
"; // Delay 10 description usleep (10000000); // start echo date ('H: I: s') again;?>
Output:
09:23:14 09:23:24
Usage of sleep and unsleep in PHP
When you need to suspend the program for several seconds, you can use sleep.
Int sleep (int $ seconds) is paused for $ seconds and then executed.
Returns zero on success, or FALSE on error. 0 is returned for success, and false is returned for error.
If the call was interrupted by a signal, sleep () returns a non-zero value. on Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API ). on other platforms, the return value will be the number of seconds left to sleep.
If the call is interrupted, this function returns a non-zero value. On windows, this value is always 192 (this value is a constant value in Windows API waiting for IO to complete WAIT_IO_COMPLETION ). The return value for other platforms is the number of seconds when sleep has not been executed.
If the specified number of seconds is negative, this function will generate a E_WARNING.
If the parameter is negative, the function produces a warning error.
When you need to suspend the execution for 1 second, you can use usleep.
Void usleep (int $ micro_seconds)
Delays program execution for the given number of micro seconds.
The usleep parameter is in microseconds and has no return value.
You can use
Time_nanosleep ()-Delay for a number of seconds and nanoseconds
You can use
Time_sleep_until ()-Make the script sleep until the specified time
For more information about the PHP sleep () function and usleep () function, see PHP!