Esempio n. 1
0
 /**
  * gets the PID number from the PID file and caches it
  *
  * @param bool $skipCache
  * @return int
  */
 protected function getPid($skipCache = false)
 {
     $skipCache = (bool) $skipCache;
     if (!$skipCache && !empty($this->pid) && $this->pid instanceof Pid) {
         return $this->pid->getPid();
     }
     $pid = $this->pidFactory->create($this->poolPidFile);
     $pidNum = $pid->getPid();
     $this->pid = $pid;
     return $pidNum;
 }
Esempio n. 2
0
 /**
  * stop all the runners and remove the pool's PID file
  */
 public function __destruct()
 {
     foreach ($this->pool as $service => $pool) {
         foreach ($pool as $i => $instance) {
             /** @var RunnerInterface $runner */
             $runner = $instance["runner"];
             $pid = $this->pidFactory->create($instance["pidFile"]);
             $this->output->writeln("<comment>Finishing runner {$i} of {$service}</comment>");
             $runner->finish($pid);
         }
     }
     if (count($this->pool) > 0) {
         $pid = $this->pidFactory->create($this->poolPidFile);
         $pid->cleanPid();
     }
 }
Esempio n. 3
0
 /**
  * @param PidInterface|string $pid
  * @return bool
  */
 public function isRunning($pid = "")
 {
     if (is_resource($this->process)) {
         // check if the process is still running
         $status = proc_get_status($this->process);
         if (!$status["running"] && ($pid instanceof PidInterface || is_string($pid) && !empty($pid))) {
             if (!$pid instanceof PidInterface) {
                 $pid = $this->pidFactory->create($pid);
             }
             // clean PID file if we didn't exit cleanly
             $pid->cleanPid();
         }
         return $status["running"];
     }
     return false;
 }