sleep
Delayed execution
The sleep()
function delays the execution of the current script by the specified number of seconds.
Note: If the specified number of seconds is negative, this function will throw an error.
Tip: In order to delay program execution by a few minutes, you should use usleep()
because sleep()
requires int. For example, sleep(0.25)
will pause the program for 0 seconds.
Delay the execution of the current script by 3 seconds:
<?php echo date ( 'h:i:s' ) . "<br>" ; // Sleep for 3 seconds sleep ( 3 ) ; // Start again echo date ( 'h:i:s' ) ; ?>
Try it yourself
sleep ( seconds )
parameter | describe |
---|---|
seconds | Required. Specifies the number of seconds to delay the script. |
If successful, return 0, otherwise return false.
If the specified description seconds is a negative number, the function will generate an E_WARNING.