Это старая версия документа!


Threading for PHP - Share Nothing

$worker = new Worker();
$task = new class extends Threaded {
    public static $a;
};
$task::$a = new class extends Threaded {};
$worker->start();
$worker->stack($task);
$worker->shutdown();
$task = new class extends Threaded {
    public static $a;
};
$task::$a = new class extends Threaded {};
$pool = new Pool(2);
$pool->submit($task);
$pool->shutdown();
<?php
 
function demanding(...$params) {
  /* you have parameters here */
  return array(rand(), rand());
}
 
class Task extends Collectable {
  public function __construct(Threaded $result, $params) {
    $this->result = $result;
    $this->params = $params;
  }
 
  public function run() {
    $this->result[] = 
      demanding(...$this->params);
  }
 
  protected $result;
  protected $params;
}
 
$pool = new Pool(16);
 
$result = new Threaded();
 
while (@$i++<16) {
  $pool->submit(
    new Task($result, $argv));
}
 
$pool->shutdown();
 
var_dump($result);
?>