Long time reader, first time poster...
I have a long-running PHP 7 process hosted on an Ubuntu 16.04 machine. It performs a variety of functions at various intervals; somethings every 2m, some ever 15m, etc. I trigger these functions based on the current epoch time compared the the 'next_time_to_run' maintained for each function. The next_time_to_run is recalculated each time the function is performed. For example, if a function is performed every 2min, then when it is triggered it simply adds 120 to the current epoch time to find the next trigger time.
I recently ran into an issue where the NTP process changed the system time rather dramatically while my process was running. As you might imagine this threw my scheduling into a tizzy. (oh yes, I said 'tizzy')
My question is this -- is it possible to register a callback/event handler/etc. that would be fired when the system time (epoch) is changed? BTW, the system clock is maintained at UTC.
Thanks oh-great-and-glorious-StackOverflow-hive-mind!
$dothing1time = time() + 120;
$dothing2time = time() + 3600;
while(1) {
$now = time();
if( $now >= $dothing1time ) { dothing1(); $dothing1time = $now + 120; }
if( $now >= $dothing2time ) { dothing2(); $dothing2time = $now + 3600; }
sleep( 30 );
}