Sometimes it is worth avoiding the local OS scheduling
framework, for example when you want something portable.
You can use localtime() and timelocal()
(from Time::Local) to convert between absolute
number of seconds and a 9 element array giving dates.
# This is from memory and almost certainly contains bugs
use Time::Local;
$now = time;
@now_array = localtime($now);
# 1:00am is tomorrow if it is after that today
if($now_array[2] >= 1)
{
$now_array[3]++;
}
# Set 1:00am in the structure
$now_array[2] = 1;
$now_array[1] = 0;
# Convert to seconds
$then = timelocal(@now_array);
# Now wait
sleep($then - $now);
It is also a good idea not to sleep for the whole time
but for an hour or so at a time (because clocks drift and
long sleeps are sometimes inaccurate. Another thing that
could be important is to arrange for your process to
be restarted if it dies and to make sure there is only
one of them running.
|