PHP | sleep( ) Function Last Updated : 03 Jul, 2018 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: http://php.net/manual/en/function.sleep.php Comment More infoAdvertise with us Next Article PHP | sleep( ) 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 readline() Function The readline() function is an inbuilt function in PHP that is used to read user input from the command line window. It provides a way to interactively prompt the user for input and capture their response as a string. Syntax: readline($prompt): string|falseParameters: This function accepts one parame 2 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 PHP | ob_start() Function Let's take a quick recap. PHP is an interpreted language thus each statement is executed one after another, therefore PHP tends to send HTML to browsers in chunks thus reducing performance. Using output buffering the generated HTML gets stored in a buffer or a string variable and is sent to the buff 2 min read PHP | touch( ) function The touch() function in PHP is an inbuilt function which is used setting the access and modification time of a specified file. The filename of the file whose access and modification time has to be set is sent as a parameter along with the time to the touch() function and it returns True on success a 3 min read PHP | date_sunset() Function The date_sunset() is an inbuilt function in PHP which is used to find the sunset time for a specified day and location. Syntax: date_sunset ( $timestamp, $format, $latitude, $longitude, $zenith, $gmtoffset ) Parameters: This function accepts four parameters as mentioned above and described below. $t 2 min read Like