在swole脚本中处理进程信号,不使用pcntl_signal()函数



我正在实现一个基于swole模块的php并行任务脚本,它作为守护进程工作。

是否可以使用Swoole函数来处理过程信号而不是pcntl_signal()?

<?php
declare(strict_types=1);
declare(ticks=1);
use SwooleCoroutine as Co;
$stopCommand = false;
$sigHandler = static function (int $sig) use (&$stopCommand)
{
switch ($sig) {
case SIGTERM:
$stopCommand = true;
break;
}
};
pcntl_signal(SIGTERM, $sigHandler);

Corun(function() use (&$stopCommand) {
$results = [];
while(true) {
//go(static function () use (&$results, &$stopCommand) {}
co::sleep(1);
if(!$results && $stopCommand) {
break;
}
}
});

Swoole Process Signal

swole Process主页

还请了解Swoole进程管理器,以及使用addServer()将进程与Swoole服务器绑定,以及Swoole进程守护进程。

最新更新