Пример #1
0
 /**
  * @param   mixed $parameter
  * @throws  \InvalidArgumentException
  */
 public function __construct($parameter = null)
 {
     if (is_null($parameter)) {
         $this->config = new Config();
     } elseif (is_int($parameter) && $parameter >= 1) {
         $this->config = new Config(array('concurrency' => $parameter));
     } elseif (is_array($parameter)) {
         $this->config = new Config($parameter);
     } else {
         throw new \InvalidArgumentException();
     }
     $this->ownerPid = getmypid();
     $this->log = new Log($this->ownerPid);
     $this->pcntl = new Pcntl();
     $this->container = new Container($this->ownerPid, $this->log, $this->config);
     $log = $this->log;
     $self = $this;
     foreach ($this->signals as $sig) {
         $this->pcntl->signal($sig, function ($sig) use($log, $self) {
             $log->info('received signal. signo: ' . $sig);
             $self->setReceivedSignal($sig);
             $log->info('--> sending a signal " to children.');
             $self->container->sendSignalToMaster($sig);
             $log->info('<-- signal handling has been completed successfully.');
             exit;
         }, false);
     }
     $this->log->info('parent pid: ' . $this->ownerPid);
 }
Пример #2
0
 /**
  * send signal to master process
  *
  * @return  void
  */
 public function sendSignalToMaster($sig = SIGTERM)
 {
     $this->log->info('----> sending signal to master. signal: ' . $sig);
     posix_kill($this->masterPid, $sig);
     $this->log->info('<---- sent signal.');
     $status = null;
     $this->pcntl->waitpid($this->masterPid, $status);
     $this->log->info('. status: ' . $status);
     $this->masterPid = null;
 }
Пример #3
0
 /**
  * @param   int     $sig
  * @return  void
  */
 public function terminate($sig)
 {
     posix_kill($this->fork->getPid(), $sig);
     $status = null;
     $this->pcntl->waitpid($this->fork->getPid(), $status);
 }