Exemple #1
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();
 }
 /**
  * Performs a heartbeat with the Worker Handler.
  */
 public function heartbeat()
 {
     $state = $this->worker->getState();
     if (!in_array($state, array(Worker::BUSY, Worker::READY))) {
         return;
     }
     // Detect manager crash.
     $timeout = 2500;
     if (!$this->worker->isExpired($timeout)) {
         // Worker is pretty active no heartbeat required.
         return;
     }
     if ($this->isWorkerHandlerReady()) {
         // Send a heartbeat.
         $this->sendToWorkerHandler(new Protocol\Heartbeat());
         return;
     }
     $expiry = 5000 + $this->delay;
     if (!$this->worker->isExpired($expiry)) {
         return;
     }
     // Expired, manager already destroyed this instance.
     $this->worker->setState(Worker::INVALID);
 }