callback = $callback; $this->callbackTime = $time; } /** * */ public function start() { register_tick_function(function(){ $this->tick(); }, true); } /** * @return int */ public function getTimeFromLastCallback() { return time() - $this->callbackTime; } /** * Call callback if time diffeence is */ public function tick() { $difference = $this->getTimeFromLastCallback(); if($difference > $this->callbackInterval) { $this->callbackTime = time(); $callback = $this->callback; $callback(); } } }