shutdown() public method

Shuts down the Worker after executing all the threaded tasks previously stacked
public shutdown ( ) : boolean
return boolean A boolean indication of success
Ejemplo n.º 1
0
 public function testWorkerStack()
 {
     $worker = new Worker();
     $work = new WorkerTestWork();
     $worker->start();
     $worker->stack($work);
     $worker->shutdown();
     $this->assertEquals($work->hasWorker, true);
 }
Ejemplo n.º 2
0
 /**
  * Stops this Worker.
  *
  * @param integer $signal [OPTIONAL] Contains the signal in the case of a PCNTL signal.
  */
 public function stop($signal = null)
 {
     if (!$this->running) {
         return;
     }
     if (null !== $signal) {
         $this->getLogger()->info('Stop called because of signal #' . $signal . '. Current state: ' . $this->worker->getState() . '.');
     } else {
         $this->getLogger()->info('Stop called: ' . $this->worker->getState() . '.');
     }
     $this->running = false;
     $this->worker->shutdown();
 }
Ejemplo n.º 3
0
 public function testWorkerGc()
 {
     $worker = new Worker();
     $work = new WorkerTestWork();
     $worker->start();
     $worker->stack($work);
     $worker->shutdown();
     $this->assertEquals(1, $worker->collect(function ($task) {
         return false;
     }));
     $this->assertEquals(0, $worker->collect(function ($task) {
         return $task->isGarbage();
     }));
 }
Ejemplo n.º 4
0
    for ($i = 0; $i <= $n; $i++) {
        $x = lcg_value() * 2 - 1;
        $y = lcg_value() * 2 - 1;
        if ($x ** 2 + $y ** 2 <= 1) {
            $np++;
        }
    }
    return $np;
};
/* make call in background thread */
$argv = [$interation / $threads];
$time_start = microtime(true);
$np_result = 0;
// Initialize and start the threads
$worker = new Worker();
$work = array();
$o = 0;
while (++$o < $threads) {
    /* items stacked could be using resources available in worker */
    $work[] = new ParallelThread($closure, $argv);
}
foreach ($work as $w) {
    $worker->stack($w);
}
$worker->start();
//$pi = 4 * $np_result / ($argv[0]*($threads));
//echo $np_result."<br>";
//echo $pi."<br>";
echo microtime(true) - $time_start;
$worker->shutdown();