PHP Function Reference

PHP sleep() Function



The PHP sleep() function is used to delay the program execution for the specified number of seconds.

Syntax

sleep(seconds)

Parameters

seconds Required. Specify the halt time in seconds.

Return Value

Returns zero on success, or false on error.

If the call was interrupted by a signal, sleep() returns a non-zero value. On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.

Exceptions

Generates an E_WARNING if the specified number of seconds is negative.

Example: sleep() example

The example below shows the usage of sleep() function.

<?php
//displaying the current time
echo date('h:i:s')."\n";

//sleep for 2 seconds
sleep(2);

//wake up and displaying the current time
echo date('h:i:s')."\n";
?>

The output of the above code will be similar to:

04:31:53
04:31:55

❮ PHP Miscellaneous Reference