How to get PHP program to sleep?
The sleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds. The sleep( ) function accepts seconds as a parameter and returns TRUE on success or FALSE on failure.
<?php
// displaying time
echo date('h:i:s')."\n" ;
// delaying execution of the script for 2 seconds
sleep(2);
// displaying time again
echo date('h:i:s');
?>
Output
06:53:48
06:53:50
06:53:50
Example
<?php
// displaying time
echo date('h:i:s')."\n" ;
// using rand() function to randomly choose
// a value and delay execution of the script
sleep(rand(1, 5));
// displaying time again
echo date('h:i:s');
?>
Output
06:53:48
06:53:52
06:53:52