Skip to content

Commit

Permalink
Merge pull request #952 from twomiao/master
Browse files Browse the repository at this point in the history
Fixed: Graceful stop and Standardized code format
  • Loading branch information
walkor authored Sep 11, 2023
2 parents 7767ef6 + db8ca24 commit c9e4100
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ protected static function parseCommand(): void
$masterIsAlive = $masterPid && posix_kill($masterPid, 0);
if ($masterIsAlive) {
// Timeout?
if (!static::$gracefulStop && time() - $startTime >= $timeout) {
if (!static::getGracefulStop() && time() - $startTime >= $timeout) {
static::log("Workerman[$startFile] stop fail");
exit;
}
Expand Down Expand Up @@ -1799,7 +1799,7 @@ protected static function reload(): void
{
// For master process.
if (static::$masterPid === posix_getpid()) {
$sig = static::$gracefulStop ? SIGUSR2 : SIGUSR1;
$sig = static::getGracefulStop() ? SIGUSR2 : SIGUSR1;
// Set reloading state.
if (static::$status !== static::STATUS_RELOADING && static::$status !== static::STATUS_SHUTDOWN) {
static::log("Workerman[" . basename(static::$startFile) . "] reloading");
Expand Down Expand Up @@ -1847,7 +1847,7 @@ protected static function reload(): void
// Send reload signal to a worker process.
posix_kill($oneWorkerPid, $sig);
// If the process does not exit after stopTimeout seconds try to kill it.
if (!static::$gracefulStop) {
if (!static::getGracefulStop()) {
Timer::add(static::$stopTimeout, '\posix_kill', [$oneWorkerPid, SIGKILL], false);
}
} // For child processes.
Expand Down Expand Up @@ -1890,15 +1890,15 @@ public static function stopAll(int $code = 0, mixed $log = ''): void
static::log("Workerman[" . basename(static::$startFile) . "] stopping ...");
$workerPidArray = static::getAllWorkerPids();
// Send stop signal to all child processes.
$sig = static::$gracefulStop ? SIGQUIT : SIGINT;
$sig = static::getGracefulStop() ? SIGQUIT : SIGINT;
foreach ($workerPidArray as $workerPid) {
// Fix exit with status 2 for php8.2
if ($sig === SIGINT && !static::$daemonize) {
Timer::add(1, '\posix_kill', [$workerPid, SIGINT], false);
} else {
posix_kill($workerPid, $sig);
}
if (!static::$gracefulStop) {
if (!static::getGracefulStop()) {
Timer::add(ceil(static::$stopTimeout), '\posix_kill', [$workerPid, SIGKILL], false);
}
}
Expand All @@ -1917,7 +1917,7 @@ public static function stopAll(int $code = 0, mixed $log = ''): void
$worker->stopping = true;
}
}
if (!static::$gracefulStop || ConnectionInterface::$statistics['connection_count'] <= 0) {
if (!static::getGracefulStop() || ConnectionInterface::$statistics['connection_count'] <= 0) {
static::$workers = [];
static::$globalEvent?->stop();

Expand Down Expand Up @@ -2468,7 +2468,7 @@ public function stop(): void
// Remove listener for server socket.
$this->unlisten();
// Close all connections for the worker.
if (static::$gracefulStop) {
if (!static::getGracefulStop()) {
foreach ($this->connections as $connection) {
$connection->close();
}
Expand Down

0 comments on commit c9e4100

Please sign in to comment.