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.
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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.