/** * Shutdown this worker * @param boolean Hard? If hard, we shouldn't wait for graceful shutdown of the running applications. * @return boolean|null Ready? */ protected function shutdown($hard = false) { $error = error_get_last(); if ($error) { if ($error['type'] === E_ERROR) { Daemon::log('W#' . $this->pid . ' crashed by error \'' . $error['message'] . '\' at ' . $error['file'] . ':' . $error['line']); } } if (Daemon::$config->logevents->value) { $this->log('event shutdown(' . ($hard ? 'HARD' : '') . ') invoked.'); } if (Daemon::$config->throwexceptiononshutdown->value) { throw new \Exception('event shutdown'); } @ob_flush(); if ($this->terminated === true) { if ($hard) { exit(0); } return; } $this->terminated = true; if ($hard) { $this->setState(Daemon::WSTATE_SHUTDOWN); exit(0); } $this->reloadReady = $this->appInstancesReloadReady(); if ($this->reload && $this->graceful) { $this->reloadReady = $this->reloadReady && microtime(TRUE) > $this->reloadTime; } if (Daemon::$config->logevents->value) { $this->log('reloadReady = ' . Debug::dump($this->reloadReady)); } Timer::remove('breakMainLoopCheck'); Timer::add(function ($event) { $self = Daemon::$process; $self->reloadReady = $self->appInstancesReloadReady(); if ($self->reload === TRUE) { $self->reloadReady = $self->reloadReady && microtime(TRUE) > $self->reloadTime; } if (!$self->reloadReady) { $event->timeout(); } else { $self->eventBase->exit(); } }, 1000000.0, 'checkReloadReady'); while (!$this->reloadReady) { $this->eventBase->loop(); } FileSystem::waitAllEvents(); // ensure that all I/O events completed before suicide exit(0); // R.I.P. }
/** * Shutdown thread * @param boolean - Hard? If hard, we shouldn't wait for graceful shutdown of the running applications. * @return boolean|null - Ready? */ public function shutdown($hard = false) { $error = error_get_last(); if ($error) { if ($error['type'] === E_ERROR) { $this->log('crashed by error \'' . $error['message'] . '\' at ' . $error['file'] . ':' . $error['line']); } } if (Daemon::$config->logevents->value) { $this->log('event shutdown(' . ($hard ? 'HARD' : '') . ') invoked.'); } if (Daemon::$config->throwexceptiononshutdown->value) { throw new \Exception('event shutdown'); } @ob_flush(); if ($this->terminated === true) { if ($hard) { exit(0); } return; } $this->terminated = true; if ($hard) { exit(0); } FileSystem::waitAllEvents(); // ensure that all I/O events completed before suicide posix_kill(posix_getppid(), SIGCHLD); // praying to Master exit(0); // R.I.P. }