Threads

Timer.class.php


<?php
  
require('TimerThread.class.php');
  
  class 
Timer {
    
private
      $threads 
= array();
      
    
public function schedule($task$delay) {
      
$this->addThread(new TimerThread($task$delay))->start();
    }
    
    
private function addThread($t) {
      
$this->threads[]= $t;
      return 
$t;
    }
    
    
public function __destruct() {
      foreach (
$this->threads as $i => $thread) {
        
$thread->join();
      }
    }
  }
?>