similar to mIRC's /timer alias
<?php
class timer {
public $callBack, $i, $t;
public function __construct($i,$t) {
$this->i = $i;
$this->t = $t;
if($i*$t > ini_get('max_execution_time') || $t < 1) {
trigger_error("max_execution_time will prevent timer from functioning completely", E_USER_WARNING);
flush();
}
}
public function add($cb,array $params=null) {
if((@function_exists($cb)&&is_string($cb))||is_array($cb)&&count($cb)==2&&@method_exists($cb[0],$cb[1]))
$this->callBack[] = array("f" => $cb, "p" => $params);
}
public function exec() {
do {
foreach($this->callBack as $cb) {
if(is_array($cb['f']))
$cb['f'] = implode("::",$cb['f']);
call_user_func_array($cb['f'],(array)$cb['p']);
}
$this->t--;
flush();
sleep($this->i);
} while($this->t != 0);
}
public function __toString() {
return __CLASS__;
}
}
?>
it follows the same basic syntax as mIRC, timer(interval, repitition) where interval is the interval between executions and repitition is the number of times its repeated(n<1 for infinite), also you can queue multiple callbacks to one timer by using add() method, i forgot to mention it in the example but you can also pass parameters in an array as a second param for add(). exec() simply executes the timer
it also throws an error if you create a timer that will take longer than max_execution_time allows the script to run for