Ejemplo n.º 1
0
 /**
  * Handles termination signals, so we can gracefully stop all servers.
  */
 public function shutdown()
 {
     if ($this->inShutdown) {
         return;
     }
     $this->inShutdown = true;
     //this method is also called during startup when something crashed, so
     //make sure we don't operate on nulls.
     $this->output->writeln('<error>Termination received, exiting.</error>');
     if ($this->controller) {
         @$this->controller->shutdown();
     }
     if ($this->web) {
         @$this->web->shutdown();
     }
     if ($this->loop) {
         $this->loop->tick();
         $this->loop->stop();
     }
     foreach ($this->slaves as $slave) {
         if (is_resource($slave['process'])) {
             proc_terminate($slave['process']);
         }
         if ($slave['pid']) {
             //make sure its dead
             posix_kill($slave['pid'], SIGKILL);
         }
     }
     exit;
 }
Ejemplo n.º 2
0
 public function bye()
 {
     if ($this->connection->isWritable()) {
         $this->connection->write(json_encode(array('cmd' => 'unregister', 'pid' => getmypid())));
         $this->connection->close();
     }
     $this->loop->stop();
 }
Ejemplo n.º 3
0
 /**
  * Shuts down the event loop. This basically exits the process.
  */
 public function shutdown()
 {
     if ($this->inShutdown) {
         return;
     }
     $this->inShutdown = true;
     $this->sendCurrentFiles();
     $this->loop->tick();
     if ($this->connection && $this->connection->isWritable()) {
         $this->connection->close();
     }
     if ($this->server) {
         @$this->server->shutdown();
     }
     if ($this->loop) {
         $this->loop->tick();
         @$this->loop->stop();
     }
     exit;
 }
Ejemplo n.º 4
0
 /**
  * Shuts down the event loop. This basically exits the process.
  */
 public function shutdown()
 {
     if ($this->inShutdown) {
         return;
     }
     if ($this->errorLogger && ($logs = $this->errorLogger->cleanLogs())) {
         $messages = array_map(function ($item) {
             //array($level, $message, $context);
             $message = $item[1];
             $context = $item[2];
             if (isset($context['file'])) {
                 $message .= ' in ' . $context['file'] . ':' . $context['line'];
             }
             if (isset($context['stack'])) {
                 foreach ($context['stack'] as $idx => $stack) {
                     $message .= PHP_EOL . sprintf("#%d: %s%s %s%s", $idx, isset($stack['class']) ? $stack['class'] . '->' : '', $stack['function'], isset($stack['file']) ? 'in' . $stack['file'] : '', isset($stack['line']) ? ':' . $stack['line'] : '');
                 }
             }
             return $message;
         }, $logs);
         error_log(implode(PHP_EOL, $messages));
     }
     $this->inShutdown = true;
     if ($this->loop) {
         $this->sendCurrentFiles();
         $this->loop->tick();
     }
     if ($this->controller && $this->controller->isWritable()) {
         $this->controller->close();
     }
     if ($this->server) {
         @$this->server->shutdown();
     }
     if ($this->loop) {
         $this->sendCurrentFiles();
         $this->loop->tick();
         @$this->loop->stop();
     }
     exit;
 }
Ejemplo n.º 5
0
 /**
  *
  */
 public function stop()
 {
     $this->loop->stop();
 }