bump version to 3.2.9 and implement safe signal handling for Swoole

This commit is contained in:
crazywhalecc
2026-07-24 12:57:31 +08:00
parent d09321f7f2
commit 52831b364d
2 changed files with 17 additions and 7 deletions

View File

@@ -29,9 +29,9 @@ class SignalListener
{
switch (Framework::getInstance()->getDriver()->getName()) {
case 'swoole':
Process::signal(SIGINT, [$this, 'onWorkerInt']);
Process::signal(SIGTERM, [$this, 'onWorkerInt']);
Process::signal(SIGHUP, [$this, 'onWorkerInt']);
$this->safeSignal(SIGINT, [$this, 'onWorkerInt']);
$this->safeSignal(SIGTERM, [$this, 'onWorkerInt']);
$this->safeSignal(SIGHUP, [$this, 'onWorkerInt']);
break;
case 'workerman':
Worker::$globalEvent->add(SIGINT, EventInterface::EV_SIGNAL, [$this, 'onWorkerInt']);
@@ -65,9 +65,9 @@ class SignalListener
Process::kill(Framework::getInstance()->getDriver()->getSwooleServer()->master_pid, SIGTERM);
}
};
Process::signal(SIGINT, $stopHandler);
Process::signal(SIGTERM, $stopHandler);
Process::signal(SIGHUP, $stopHandler);
$this->safeSignal(SIGINT, $stopHandler);
$this->safeSignal(SIGTERM, $stopHandler);
$this->safeSignal(SIGHUP, $stopHandler);
} elseif ($driver === 'workerman') {
if (!extension_loaded('pcntl') || !extension_loaded('posix')) {
logger()->error('请安装 pcntl 和 posix 扩展以支持信号监听');
@@ -130,6 +130,16 @@ class SignalListener
}
}
/**
* 注册 Swoole 信号处理器,信号已被 Swoole 自身注册时跳过
*/
private function safeSignal(int $signo, callable $handler): void
{
if (!@Process::signal($signo, $handler)) {
logger()->debug('信号 {signo} 已被系统注册,跳过监听', ['signo' => $signo]);
}
}
/**
* 按5次Ctrl+C后强行杀死框架的处理函数
*/

View File

@@ -50,7 +50,7 @@ class Framework
public const VERSION_ID = 727;
/** @var string 版本名称 */
public const VERSION = '3.2.8';
public const VERSION = '3.2.9';
/**
* @var RuntimePreferences 运行时偏好(环境信息&参数)