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');

?>
09:08:20
09:08:21

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');

?>
09:08:21
09:08:22

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

Home Menu