TimerThread.class.php
<?php
require('TimerTask.class.php');
class TimerThread extends Thread {
private
$task = NULL,
$delay = 0,
$interval = 0;
public function __construct($task, $delay, $interval= -1) {
$this->task= $task;
$this->delay= $delay;
$this->interval= $interval;
}
public function run() {
usleep($this->delay * 1000); // Initial delay
if (!$this->task->run()) return ;
if ($this->interval < 0) return FALSE;
do { // Interval
usleep($this->interval * 1000);
} while ($this->task->run());
return TRUE;
}
}
?>