Threads

simple.php


<?php
  
class SimpleThread extends Thread {
    
public
      $name 
'';
      
    
private
      $i    
0;
    
    
public function __construct($name) {
      
$this->name$name;
      
$this->i0;          // workaround
    
}
    
    
public function run() {
      for (
$this->i0$this->5$this->i++) {
        
printf("%d %s\n"$this->i$this->name);
        
usleep(rand(14) * 100000);
      }
      
printf("DONE: %s\n"$this->name);
    }
  }
  
  
$k= new SimpleThread('Karlsruhe');
  
$k->start();
  
$b= new SimpleThread('Berlin');
  
$b->start();
  
$n= new SimpleThread('New York');
  
$n->start();
  
sleep(10);
?>