PHP | time_sleep_until( ) Function
Last Updated :
21 Jun, 2018
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 returns TRUE on success or FALSE on failure.
Syntax:
time_sleep_until(timestamp)
Parameters Used: The time_sleep_until() function in PHP accepts one parameter timestamp . It is a mandatory parameter which specifies the time to wake.
Return Value: It returns TRUE on success or FALSE on failure.
Errors And Exceptions:
- If the specified timestamp is in the past, this function will generate an E_WARNING.
- All signals are delivered after the script wakes up.
- This function throws an error if the specified number is negative.
Examples:
Input : echo date('h:i:s');
time_sleep_until(time()+5);
echo date('h:i:s');
Output: 07:23:26
07:23:31
Input : echo date('h:i:s');
time_sleep_until(time()+ rand(1, 3));
echo date('h:i:s');
Output : 07:21:55
07:21:57
Below programs illustrate the time_sleep_until() function:
Program 1:
<?php
echo date ( 'h:i:s' );
time_sleep_until(time()+5);
echo ( "\n" );
echo date ( 'h:i:s' );
?>
|
Output:
06:50:04
06:50:08
Program 2:
<?php
echo date ( 'h:i:s' );
time_sleep_until(time()+ rand(1, 3));
echo ( "\n" );
echo date ( 'h:i:s' );
?>
|
Output:
06:50:14
06:50:15
Program 3:
<?php
time_sleep_until(time()-2);
echo ( "\n" );
echo date ( 'h:i:s' );
?>
|
Reference : http://php.net/manual/en/function.time-sleep-until.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...