mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-25 17:45:34 +08:00
bump version to 3.2.9 and implement safe signal handling for Swoole
This commit is contained in:
@@ -29,9 +29,9 @@ class SignalListener
|
|||||||
{
|
{
|
||||||
switch (Framework::getInstance()->getDriver()->getName()) {
|
switch (Framework::getInstance()->getDriver()->getName()) {
|
||||||
case 'swoole':
|
case 'swoole':
|
||||||
Process::signal(SIGINT, [$this, 'onWorkerInt']);
|
$this->safeSignal(SIGINT, [$this, 'onWorkerInt']);
|
||||||
Process::signal(SIGTERM, [$this, 'onWorkerInt']);
|
$this->safeSignal(SIGTERM, [$this, 'onWorkerInt']);
|
||||||
Process::signal(SIGHUP, [$this, 'onWorkerInt']);
|
$this->safeSignal(SIGHUP, [$this, 'onWorkerInt']);
|
||||||
break;
|
break;
|
||||||
case 'workerman':
|
case 'workerman':
|
||||||
Worker::$globalEvent->add(SIGINT, EventInterface::EV_SIGNAL, [$this, 'onWorkerInt']);
|
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::kill(Framework::getInstance()->getDriver()->getSwooleServer()->master_pid, SIGTERM);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Process::signal(SIGINT, $stopHandler);
|
$this->safeSignal(SIGINT, $stopHandler);
|
||||||
Process::signal(SIGTERM, $stopHandler);
|
$this->safeSignal(SIGTERM, $stopHandler);
|
||||||
Process::signal(SIGHUP, $stopHandler);
|
$this->safeSignal(SIGHUP, $stopHandler);
|
||||||
} elseif ($driver === 'workerman') {
|
} elseif ($driver === 'workerman') {
|
||||||
if (!extension_loaded('pcntl') || !extension_loaded('posix')) {
|
if (!extension_loaded('pcntl') || !extension_loaded('posix')) {
|
||||||
logger()->error('请安装 pcntl 和 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后强行杀死框架的处理函数
|
* 按5次Ctrl+C后强行杀死框架的处理函数
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Framework
|
|||||||
public const VERSION_ID = 727;
|
public const VERSION_ID = 727;
|
||||||
|
|
||||||
/** @var string 版本名称 */
|
/** @var string 版本名称 */
|
||||||
public const VERSION = '3.2.8';
|
public const VERSION = '3.2.9';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var RuntimePreferences 运行时偏好(环境信息&参数)
|
* @var RuntimePreferences 运行时偏好(环境信息&参数)
|
||||||
|
|||||||
Reference in New Issue
Block a user