timer.php
<?php
require('Timer.class.php');
class RemindTask extends TimerTask {
public function run() {
printf("Reminder: It's now %s!\n", date('H:i:s'));
// Return FALSE to indicate no more calls are to be made
return FALSE;
}
}
class Reminder {
private
$timer = NULL;
public function __construct($seconds) {
$this->timer= new Timer();
$this->timer->schedule(new RemindTask(), $seconds * 1000);
}
}
// {{{ main
print("About to schedule task.\n");
$r= new Reminder(5);
printf("Task scheduled at %s.\n", date('H:i:s'));
// Do something for at least 6 seconds.
foreach (range(1, 6) as $i) {
print(date("H:i:s\n"));
sleep(1);
}
print("Done.\n");
// }}}
?>