note 99445 modified in function.sleep by danbrown
| From: | danbrown@php.net | Date: | Wed, 18 Aug 2010 15:53:01 +0000 |
| Subject: | note 99445 modified in function.sleep by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171811@lists.php.net to get a copy of this message | ||
Since sleep() can be interrupted by signals i've made a function which can also be interrupted,
but will continue sleeping after the signal arrived (and possibly was handled by callback).
It's very useful when you write daemons and need sleep() function to work as long as you
'ordered', but have an ability to accept signals during sleeping.
<?php
function my_sleep($seconds)
{
$start = microtime(true);
for ($i = 1; $i <= $seconds; $i ++) {
@time_sleep_until($start + $i);
}
}
?>
--was--
Since sleep() can be interrupted by signals i've made a function which can also be interrupted,
but will continue sleeping after the signal arrived (and possibly was handled by callback).
It's very useful when you write daemons and need sleep() function to work as long as you
'ordered', but have an ability to accept signals during sleeping.
function my_sleep($seconds)
{
$start = microtime(true);
for ($i = 1; $i <= $seconds; $i ++) {
@time_sleep_until($start + $i);
}
}
http://php.net/manual/en/function.sleep.php