. * * * ************************************************************************ * * Tools/timer.inc.php * * timer functions */ $timers['id']=0; function timer_loop() { global $timers; $mtime = microtime(true); $ret = false; foreach ($timers as $id => $timer) { if(($timer['expire'] - 0.00019) <= $mtime) { //we expire a timer 0,19 ms before (to reduce timer desyncs) if((is_array($timer['function']) && method_exists($timer['function'][0],$timer['function'][1])) || (!is_array($timer['function']) && function_exists($timer['function']))) { call_user_func_array($timer['function'],$timer['params']); } $ret = true; unset($timers[$id]); } } return $ret; } function timer($seconds,$command,$parameter) { global $timers; $new['expire'] = microtime(true) + $seconds; $new['function'] = $command; $new['params'] = $parameter; while(isset($timers[$timers['id']])|| !isset($timers['id'])) { $timers['id']++; if($timers['id'] > 9999999) $timers['id'] = 0; } $timers[$timers['id']] = $new; return $timers['id']; } function utimer($seconds,$command,$parameter) { global $timers; $new['expire'] = microtime(true) + ($seconds / 1000); $new['function'] = $command; $new['params'] = $parameter; while($timers[$timers['id']] || !$timers['id']) { $timers['id']++; if($timers['id'] > 9999999) $timers['id'] = 0; } $timers[$timers['id']] = $new; return $timers['id']; } function kill_timer($id) { global $timers; unset($timers[$id]); } $timers['id']=0; ?>