The usleep
method can be used to make the program execution
1000000
micro second =1
second
usleep(int $microseconds): void
The microseconds
argument denotes the number of microseconds the program execution needs to wait. This method does not return any value.
<?phpecho "Time is : ".date('h:i:s'). "\n";usleep(3000000); // sleeps for 3 seconods.echo "Time is : ".date('h:i:s'). "\n";?>
In the code above, we did the following:
We printed the current time using the date('h:i:s')
.
We then called the usleep(3000000)
method to make the program execution sleep for 3
seconds.
We printed the time. This time will be 3
seconds after the first printed time.
Some Operating systems do not support usleep
if the sleep time is more than 1
second
If the sleep time requirement comes in seconds, then use the sleep(seconds)
method instead of the usleep(microseconds)
method.
The sleeping time may be longer on the Windows
Operating system than the provided microseconds.