Menu Home

time_sleep_until

osbo.com | PHP | Functions | time_sleep_until

Make the script sleep until the specified time

Syntax

time_sleep_until ( float $timestamp ) : bool

Parameters

timestamp

The timestamp when the script should wake.

Return

Returns TRUE on success or FALSE on failure.

Examples

1

<?

echo date('h:i:s') . PHP_EOL;

// 1 second after now
$timestamp = time() + 1;

time_sleep_until($timestamp);

echo date('h:i:s');

?>
08:33:51
08:33:52

2

<?

echo date('h:i:s') . PHP_EOL;

// 1 second after now
$timestamp = strtotime("1 second");

time_sleep_until($timestamp);

echo date('h:i:s');

?>
08:33:52
08:33:53

3

<?

// 1 second before now
$timestamp = time() - 1;

// returns false and generates a warning
$bool = time_sleep_until($timestamp);
var_dump($bool);

?>
bool(false)

4

<?

// 1 second after now
$timestamp = time() + 1;

$bool = time_sleep_until($timestamp);
var_dump($bool);

?>
bool(true)

PHP