PHP Usleep Function
Syntax
usleep($time);
Parameter | Description |
Time | Time in microseconds |
Definition & Usage
Usleep function is used to pause the execution of PHP script for the $number amount of time, time must be in microseconds. For example, if you want to pause script for 1 second write like that
usleep(1000000);
Note: Usleep function does not return anything.
Example of usleep function
<?php usleep(3000000); echo "Result after three second."; ?>
Output
Result after three second.
In the above example, the result will be appeared after 3 second.
More example of usleep function
<?php echo "Start time:"; echo date('h:i:s') . "
"; usleep(4000000); echo "End time:"; echo date('h:i:s'); ?>
Output
Start time:11:30:39
End time:11:30:43
End time:11:30:43
In the above example, You can see the start and end time of the script and the difference between both times is 4 second.