/** * 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; }
/** * 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; }
/** * 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; }