From 6274c34179a8bea351093513541df170d208f392 Mon Sep 17 00:00:00 2001 From: walkor Date: Tue, 3 Sep 2024 10:55:58 +0800 Subject: [PATCH] Log optimization --- src/Worker.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Worker.php b/src/Worker.php index 8ed426fd..02bec977 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -1032,7 +1032,7 @@ protected static function parseCommand(): void // Master process will send SIGIOT signal to all child processes. posix_kill($masterPid, SIGIOT); // Waiting a moment. - usleep(500000); + sleep(1); // Clear terminal. if ($mode === '-d') { static::safeEcho("\33[H\33[2J\33(B\33[m", true); @@ -1265,12 +1265,12 @@ protected static function signalHandler(int $signal): void case SIGHUP: case SIGTSTP: static::$gracefulStop = false; - static::stopAll(0, "received signal: $signal"); + static::stopAll(0, "received signal $signal"); break; // Graceful stop. case SIGQUIT: static::$gracefulStop = true; - static::stopAll(0, "received signal: $signal"); + static::stopAll(0, "received signal $signal"); break; // Reload. case SIGUSR2: @@ -1919,14 +1919,13 @@ protected static function reload(): void */ public static function stopAll(int $code = 0, mixed $log = ''): void { - if ($log) { - static::log($log); - } - static::$status = static::STATUS_SHUTDOWN; // For master process. if (DIRECTORY_SEPARATOR === '/' && static::$masterPid === posix_getpid()) { - static::log("Workerman[" . basename(static::$startFile) . "] stopping, code [$code]"); + if ($log) { + static::log("Workerman[" . basename(static::$startFile) . "] $log"); + } + static::log("Workerman[" . basename(static::$startFile) . "] stopping" . ($code ? ", code [$code]" : '')); $workerPidArray = static::getAllWorkerPids(); // Send stop signal to all child processes. $sig = static::getGracefulStop() ? SIGQUIT : SIGINT; @@ -1944,6 +1943,9 @@ public static function stopAll(int $code = 0, mixed $log = ''): void Timer::add(1, static::checkIfChildRunning(...)); } // For child processes. else { + if ($code && $log) { + static::log($log); + } // Execute exit. $workers = array_reverse(static::$workers); array_walk($workers, static fn (Worker $worker) => $worker->stop());