/**
  * Blocks until call is complete.
  *
  * @throws \Exception        If this function is called before start()
  * @throws \RuntimeException
  *
  * @return string
  */
 public function wait()
 {
     if ($this->processAsync == null) {
         throw new \Exception('You must run `start` before running `wait`');
     }
     // blocks here until process completes
     $this->processAsync->wait();
     if (!$this->processAsync->isSuccessful()) {
         throw new \RuntimeException($this->processAsync->getErrorOutput());
     }
     return $this->processAsync->getOutput();
 }
Ejemplo n.º 2
0
 /**
  * start the same number processes and kill the old sub process
  * just like nginx -s reload
  * this method will block until all the old process exit;
  *
  * @param bool $block
  */
 public function reload($block = true)
 {
     $old_process = $this->processes;
     for ($i = 0; $i < $this->max; $i++) {
         $process = new Process($this->runnable);
         $process->start();
         $this->processes[$process->getPid()] = $process;
     }
     foreach ($old_process as $process) {
         $process->shutdown();
         $process->wait($block);
         unset($this->processes[$process->getPid()]);
     }
 }