PHP | sleep( ) Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share 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 | time_sleep_until( ) 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 | 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 | popen( ) Function The popen() function used to open a pipe to the program specified by the user using the command parameter. It returns a file pointer which is identical to that returned by fopen(), but it is unidirectional in nature i.e it can be only used for reading or writing. The popen() pointer can be used with 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 readfile( ) Function The readfile() function in PHP reads a file and writes its contents directly to the output buffer (usually the browser). Itâs an easy way to show a file without reading it line by line yourself.If thereâs a problem reading the file, like if it doesnât exist, PHP will usually show an error message. T 3 min read PHP rand() Function In this article, we will see how to get the random number using the rand() function in PHP, along with knowing its implementation through the example. The rand() is an inbuilt function in PHP used to generate a random number ie., it can generate a random integer value in the range [min, max]. Syntax 2 min read Like