Skip to content

Commit

Permalink
Log optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Sep 3, 2024
1 parent 9e4ecd9 commit 6274c34
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit 6274c34

Please sign in to comment.