PHP | sleep( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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. If the call is interrupted by a signal, sleep() function returns a non-zero value. On Windows, this value will always be 192 whereas, on other platforms, the return value will be the number of seconds left to sleep. Syntax: sleep($seconds) Parameters Used: The sleep() function in PHP accepts one parameter. $seconds : It is a mandatory parameter which specifies the number of seconds. Return Value: It returns TRUE on success or FALSE on failure. Errors And Exceptions: If the call is interrupted by a signal, sleep() function returns a non-zero value. The value of seconds passed as parameter should be non-negative else this function will generate a E_WARNING.. Below programs illustrate the sleep() function: Program 1: php <?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 Program 2: php <?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 Reference: https://www.php.net/manual/en/function.sleep.php Comment More infoAdvertise with us Next Article PHP | usleep( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP | usleep( ) Function The usleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for specific microseconds. It is similar to the sleep() function which delays execution of the current script for a specified number of seconds, unlike the usleep() function which delays th 2 min read PHP | usleep( ) Function The usleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for specific microseconds. It is similar to the sleep() function which delays execution of the current script for a specified number of seconds, unlike the usleep() function which delays th 2 min read PHP | usleep( ) Function The usleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for specific microseconds. It is similar to the sleep() function which delays execution of the current script for a specified number of seconds, unlike the usleep() function which delays th 2 min read PHP | time() Function The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP. Syntax: int time() Parameter: This function does not accepts any parameter 2 min read PHP | time_sleep_until( ) Function The time_sleep_until() function in PHP is an inbuilt function which is used to delay execution of the current script until the specified time. The time_sleep_until( ) function accepts timestamp as a parameter and this timestamp denotes when the script should wake. The time_sleep_until( ) function re 2 min read PHP | time_sleep_until( ) Function The time_sleep_until() function in PHP is an inbuilt function which is used to delay execution of the current script until the specified time. The time_sleep_until( ) function accepts timestamp as a parameter and this timestamp denotes when the script should wake. The time_sleep_until( ) function re 2 min read Like