|
@@ -586,7 +586,7 @@ class Worker
|
|
|
protected static function init()
|
|
protected static function init()
|
|
|
{
|
|
{
|
|
|
\set_error_handler(function ($code, $msg, $file, $line) {
|
|
\set_error_handler(function ($code, $msg, $file, $line) {
|
|
|
- Worker::safeEcho("$msg in file $file on line $line\n");
|
|
|
|
|
|
|
+ static::safeEcho("$msg in file $file on line $line\n");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Start file.
|
|
// Start file.
|
|
@@ -1178,6 +1178,9 @@ class Worker
|
|
|
// Reload.
|
|
// Reload.
|
|
|
case \SIGUSR2:
|
|
case \SIGUSR2:
|
|
|
case \SIGUSR1:
|
|
case \SIGUSR1:
|
|
|
|
|
+ if (static::$status === static::STATUS_RELOADING || static::$status === static::STATUS_SHUTDOWN) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
static::$gracefulStop = $signal === \SIGUSR2;
|
|
static::$gracefulStop = $signal === \SIGUSR2;
|
|
|
static::$pidsToRestart = static::getAllWorkerPids();
|
|
static::$pidsToRestart = static::getAllWorkerPids();
|
|
|
static::reload();
|
|
static::reload();
|
|
@@ -1723,6 +1726,7 @@ class Worker
|
|
|
{
|
|
{
|
|
|
// For master process.
|
|
// For master process.
|
|
|
if (static::$masterPid === \posix_getpid()) {
|
|
if (static::$masterPid === \posix_getpid()) {
|
|
|
|
|
+ $sig = static::$gracefulStop ? \SIGUSR2 : \SIGUSR1;
|
|
|
// Set reloading state.
|
|
// Set reloading state.
|
|
|
if (static::$status !== static::STATUS_RELOADING && static::$status !== static::STATUS_SHUTDOWN) {
|
|
if (static::$status !== static::STATUS_RELOADING && static::$status !== static::STATUS_SHUTDOWN) {
|
|
|
static::log("Workerman[" . \basename(static::$startFile) . "] reloading");
|
|
static::log("Workerman[" . \basename(static::$startFile) . "] reloading");
|
|
@@ -1738,29 +1742,26 @@ class Worker
|
|
|
}
|
|
}
|
|
|
static::initId();
|
|
static::initId();
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- $sig = static::$gracefulStop ? \SIGUSR2 : \SIGUSR1;
|
|
|
|
|
-
|
|
|
|
|
- // Send reload signal to all child processes.
|
|
|
|
|
- $reloadablePidArray = [];
|
|
|
|
|
- foreach (static::$pidMap as $workerId => $workerPidArray) {
|
|
|
|
|
- $worker = static::$workers[$workerId];
|
|
|
|
|
- if ($worker->reloadable) {
|
|
|
|
|
- foreach ($workerPidArray as $pid) {
|
|
|
|
|
- $reloadablePidArray[$pid] = $pid;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- foreach ($workerPidArray as $pid) {
|
|
|
|
|
- // Send reload signal to a worker process which reloadable is false.
|
|
|
|
|
- \posix_kill($pid, $sig);
|
|
|
|
|
|
|
+ // Send reload signal to all child processes.
|
|
|
|
|
+ $reloadablePidArray = [];
|
|
|
|
|
+ foreach (static::$pidMap as $workerId => $workerPidArray) {
|
|
|
|
|
+ $worker = static::$workers[$workerId];
|
|
|
|
|
+ if ($worker->reloadable) {
|
|
|
|
|
+ foreach ($workerPidArray as $pid) {
|
|
|
|
|
+ $reloadablePidArray[$pid] = $pid;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ foreach ($workerPidArray as $pid) {
|
|
|
|
|
+ // Send reload signal to a worker process which reloadable is false.
|
|
|
|
|
+ \posix_kill($pid, $sig);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // Get all pids that are waiting reload.
|
|
|
|
|
+ static::$pidsToRestart = \array_intersect(static::$pidsToRestart, $reloadablePidArray);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Get all pids that are waiting reload.
|
|
|
|
|
- static::$pidsToRestart = \array_intersect(static::$pidsToRestart, $reloadablePidArray);
|
|
|
|
|
-
|
|
|
|
|
// Reload complete.
|
|
// Reload complete.
|
|
|
if (empty(static::$pidsToRestart)) {
|
|
if (empty(static::$pidsToRestart)) {
|
|
|
if (static::$status !== static::STATUS_SHUTDOWN) {
|
|
if (static::$status !== static::STATUS_SHUTDOWN) {
|
|
@@ -1818,7 +1819,7 @@ class Worker
|
|
|
$sig = static::$gracefulStop ? \SIGQUIT : \SIGINT;
|
|
$sig = static::$gracefulStop ? \SIGQUIT : \SIGINT;
|
|
|
foreach ($workerPidArray as $workerPid) {
|
|
foreach ($workerPidArray as $workerPid) {
|
|
|
// Fix exit with status 2 for php8.2
|
|
// Fix exit with status 2 for php8.2
|
|
|
- if ($sig === \SIGINT && !Worker::$daemonize) {
|
|
|
|
|
|
|
+ if ($sig === \SIGINT && !static::$daemonize) {
|
|
|
Timer::add(1, '\posix_kill', [$workerPid, \SIGINT], false);
|
|
Timer::add(1, '\posix_kill', [$workerPid, \SIGINT], false);
|
|
|
} else {
|
|
} else {
|
|
|
\posix_kill($workerPid, $sig);
|
|
\posix_kill($workerPid, $sig);
|
|
@@ -2423,7 +2424,7 @@ class Worker
|
|
|
try {
|
|
try {
|
|
|
($this->onWorkerStop)($this);
|
|
($this->onWorkerStop)($this);
|
|
|
} catch (Throwable $e) {
|
|
} catch (Throwable $e) {
|
|
|
- Worker::log($e);
|
|
|
|
|
|
|
+ static::log($e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// Remove listener for server socket.
|
|
// Remove listener for server socket.
|
|
@@ -2458,7 +2459,7 @@ class Worker
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TcpConnection.
|
|
// TcpConnection.
|
|
|
- $connection = new TcpConnection(Worker::$globalEvent, $newSocket, $remoteAddress);
|
|
|
|
|
|
|
+ $connection = new TcpConnection(static::$globalEvent, $newSocket, $remoteAddress);
|
|
|
$this->connections[$connection->id] = $connection;
|
|
$this->connections[$connection->id] = $connection;
|
|
|
$connection->worker = $this;
|
|
$connection->worker = $this;
|
|
|
$connection->protocol = $this->protocol;
|
|
$connection->protocol = $this->protocol;
|