|
@@ -836,7 +836,7 @@ class Worker
|
|
|
|
|
|
|
|
// Event-loop name.
|
|
// Event-loop name.
|
|
|
$eventLoopName = $worker->eventLoop ?: static::$eventLoopClass;
|
|
$eventLoopName = $worker->eventLoop ?: static::$eventLoopClass;
|
|
|
- $worker->context->eventLoopName = str_starts_with($eventLoopName, 'Workerman\\Events\\') ? strtolower(substr($eventLoopName, 17)) : $eventLoopName;
|
|
|
|
|
|
|
+ $worker->context->eventLoopName = strtolower(substr($eventLoopName, strrpos($eventLoopName, '\\') + 1));
|
|
|
|
|
|
|
|
// Status name.
|
|
// Status name.
|
|
|
$worker->context->statusState = '<g> [OK] </g>';
|
|
$worker->context->statusState = '<g> [OK] </g>';
|
|
@@ -1004,7 +1004,7 @@ class Worker
|
|
|
public static function getUiColumns(): array
|
|
public static function getUiColumns(): array
|
|
|
{
|
|
{
|
|
|
return [
|
|
return [
|
|
|
- 'event' => 'eventLoopName',
|
|
|
|
|
|
|
+ 'event-loop' => 'eventLoopName',
|
|
|
'proto' => 'transport',
|
|
'proto' => 'transport',
|
|
|
'user' => 'user',
|
|
'user' => 'user',
|
|
|
'worker' => 'name',
|
|
'worker' => 'name',
|
|
@@ -1048,7 +1048,7 @@ class Worker
|
|
|
|
|
|
|
|
// Check argv;
|
|
// Check argv;
|
|
|
$startFile = basename(static::$startFile);
|
|
$startFile = basename(static::$startFile);
|
|
|
- $usage = "Usage: php yourfile <command> [mode]\nCommands: \nstart\t\tStart worker in USER mode.\n\t\tUse mode -d to start in DAEMON mode.\nstop\t\tStop worker.\n\t\tUse mode -g to stop gracefully.\nrestart\t\tRestart workers.\n\t\tUse mode -d to start in DAEMON mode.\n\t\tUse mode -g to stop gracefully.\nreload\t\tReload codes.\n\t\tUse mode -g to reload gracefully.\nstatus\t\tGet worker status.\n\t\tUse mode -d to show live status.\nconnections\tGet worker connections.\n";
|
|
|
|
|
|
|
+ $usage = "Usage: php yourfile <command> [mode]\nCommands: \nstart\t\tStart worker in DEBUG mode.\n\t\tUse mode -d to start in DAEMON mode.\nstop\t\tStop worker.\n\t\tUse mode -g to stop gracefully.\nrestart\t\tRestart workers.\n\t\tUse mode -d to start in DAEMON mode.\n\t\tUse mode -g to stop gracefully.\nreload\t\tReload codes.\n\t\tUse mode -g to reload gracefully.\nstatus\t\tGet worker status.\n\t\tUse mode -d to show live status.\nconnections\tGet worker connections.\n";
|
|
|
$availableCommands = [
|
|
$availableCommands = [
|
|
|
'start',
|
|
'start',
|
|
|
'stop',
|
|
'stop',
|
|
@@ -1081,7 +1081,7 @@ class Worker
|
|
|
if ($mode === '-d' || static::$daemonize) {
|
|
if ($mode === '-d' || static::$daemonize) {
|
|
|
$modeStr = 'in DAEMON mode';
|
|
$modeStr = 'in DAEMON mode';
|
|
|
} else {
|
|
} else {
|
|
|
- $modeStr = 'in USER mode';
|
|
|
|
|
|
|
+ $modeStr = 'in DEBUG mode';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
static::log("Workerman[$startFile] $command $modeStr");
|
|
static::log("Workerman[$startFile] $command $modeStr");
|
|
@@ -1344,12 +1344,12 @@ class Worker
|
|
|
case SIGHUP:
|
|
case SIGHUP:
|
|
|
case SIGTSTP:
|
|
case SIGTSTP:
|
|
|
static::$gracefulStop = false;
|
|
static::$gracefulStop = false;
|
|
|
- static::stopAll(0, "received signal $signal");
|
|
|
|
|
|
|
+ static::stopAll(0, 'received signal ' . static::getSignalName($signal));
|
|
|
break;
|
|
break;
|
|
|
// Graceful stop.
|
|
// Graceful stop.
|
|
|
case SIGQUIT:
|
|
case SIGQUIT:
|
|
|
static::$gracefulStop = true;
|
|
static::$gracefulStop = true;
|
|
|
- static::stopAll(0, "received signal $signal");
|
|
|
|
|
|
|
+ static::stopAll(0, 'received signal ' . static::getSignalName($signal));
|
|
|
break;
|
|
break;
|
|
|
// Reload.
|
|
// Reload.
|
|
|
case SIGUSR2:
|
|
case SIGUSR2:
|
|
@@ -1373,6 +1373,28 @@ class Worker
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Get signal name.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $signal
|
|
|
|
|
+ * @return string
|
|
|
|
|
+ */
|
|
|
|
|
+ protected static function getSignalName(int $signal): string
|
|
|
|
|
+ {
|
|
|
|
|
+ return match ($signal) {
|
|
|
|
|
+ SIGINT => 'SIGINT',
|
|
|
|
|
+ SIGTERM => 'SIGTERM',
|
|
|
|
|
+ SIGHUP => 'SIGHUP',
|
|
|
|
|
+ SIGTSTP => 'SIGTSTP',
|
|
|
|
|
+ SIGQUIT => 'SIGQUIT',
|
|
|
|
|
+ SIGUSR1 => 'SIGUSR1',
|
|
|
|
|
+ SIGUSR2 => 'SIGUSR2',
|
|
|
|
|
+ SIGIOT => 'SIGIOT',
|
|
|
|
|
+ SIGIO => 'SIGIO',
|
|
|
|
|
+ default => $signal,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Run as daemon mode.
|
|
* Run as daemon mode.
|
|
|
*/
|
|
*/
|
|
|
protected static function daemonize(): void
|
|
protected static function daemonize(): void
|
|
@@ -2084,20 +2106,20 @@ class Worker
|
|
|
count(static::$pidMap) . ' workers ' . count(static::getAllWorkerPids()) . " processes\n",
|
|
count(static::$pidMap) . ' workers ' . count(static::getAllWorkerPids()) . " processes\n",
|
|
|
FILE_APPEND);
|
|
FILE_APPEND);
|
|
|
file_put_contents(static::$statisticsFile,
|
|
file_put_contents(static::$statisticsFile,
|
|
|
- str_pad('name', static::getUiColumnLength('maxWorkerNameLength')) . " event exit_status exit_count\n", FILE_APPEND);
|
|
|
|
|
|
|
+ str_pad('name', static::getUiColumnLength('maxWorkerNameLength')) . " event-loop exit_status exit_count\n", FILE_APPEND);
|
|
|
foreach (static::$pidMap as $workerId => $workerPidArray) {
|
|
foreach (static::$pidMap as $workerId => $workerPidArray) {
|
|
|
$worker = static::$workers[$workerId];
|
|
$worker = static::$workers[$workerId];
|
|
|
if (isset(static::$globalStatistics['worker_exit_info'][$workerId])) {
|
|
if (isset(static::$globalStatistics['worker_exit_info'][$workerId])) {
|
|
|
foreach (static::$globalStatistics['worker_exit_info'][$workerId] as $workerExitStatus => $workerExitCount) {
|
|
foreach (static::$globalStatistics['worker_exit_info'][$workerId] as $workerExitStatus => $workerExitCount) {
|
|
|
file_put_contents(static::$statisticsFile,
|
|
file_put_contents(static::$statisticsFile,
|
|
|
str_pad($worker->name, static::getUiColumnLength('maxWorkerNameLength')) . " " .
|
|
str_pad($worker->name, static::getUiColumnLength('maxWorkerNameLength')) . " " .
|
|
|
- str_pad($worker->context->eventLoopName, 12) . " " .
|
|
|
|
|
|
|
+ str_pad($worker->context->eventLoopName, 14) . " " .
|
|
|
str_pad((string)$workerExitStatus, 16) . str_pad((string)$workerExitCount, 16) . "\n", FILE_APPEND);
|
|
str_pad((string)$workerExitStatus, 16) . str_pad((string)$workerExitCount, 16) . "\n", FILE_APPEND);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
file_put_contents(static::$statisticsFile,
|
|
file_put_contents(static::$statisticsFile,
|
|
|
str_pad($worker->name, static::getUiColumnLength('maxWorkerNameLength')) . " " .
|
|
str_pad($worker->name, static::getUiColumnLength('maxWorkerNameLength')) . " " .
|
|
|
- str_pad($worker->context->eventLoopName, 12) . " " .
|
|
|
|
|
|
|
+ str_pad($worker->context->eventLoopName, 14) . " " .
|
|
|
str_pad('0', 16) . str_pad('0', 16) . "\n", FILE_APPEND);
|
|
str_pad('0', 16) . str_pad('0', 16) . "\n", FILE_APPEND);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|