The sleep method can be used to suspend the execution of a program for a specific amount of time.
sleep(int $seconds): int
The seconds argument denotes the number of seconds the program execution needs to wait.
The value should be positive; otherwise, the function will produce E_WARNING.
This method returns 0 upon success and false upon error.
If the waiting is interrupted by a
signal, then the method returns a non-zero value. This value will always be192for Windows. For other operating systems, this value will be the number of seconds left to sleep.
<?phpecho "Time is : ".date('h:i:s'). "\n";$val = sleep(2);echo "Time is : ".date('h:i:s'). "\n";echo "Sleep method returned ". $val. "\n";?>
In the code above:
We print the current time using date('h:i:s').
We then call the sleep(2) method to make the program execution pause for two seconds.
We print the time and value returned by the sleep method.