Current Location: Home> Function Categories> sleep

sleep

Delayed execution
Name:sleep
Category:Miscellaneous
Programming Language:php
One-line Description:Delay code execution by the specified number of seconds.

Definition and usage

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.

Example

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

grammar

 sleep ( seconds )
parameter describe
seconds Required. Specifies the number of seconds to delay the script.

Return value

If successful, return 0, otherwise return false.

Error/Exception

If the specified description seconds is a negative number, the function will generate an E_WARNING.

Similar Functions
Popular Articles