This commit is contained in:
2021-08-19 17:41:10 +08:00
parent 99b4aee754
commit 633d1fce44
3 changed files with 69 additions and 22 deletions
+13 -7
View File
@@ -4,6 +4,7 @@ namespace Server\Abstracts;
use JetBrains\PhpStorm\Pure;
use Kiri\Kiri;
use Swoole\Coroutine;
use Swoole\Process;
@@ -43,18 +44,23 @@ abstract class CustomProcess implements \Server\SInterface\CustomProcess
*/
public function signListen(Process $process): void
{
if (!$this->enableSwooleCoroutine) {
Process::signal(SIGTERM | SIGKILL, function ($signo)
use ($process) {
$this->onProcessStop();
$this->waiteExit($process);
if (Coroutine::getCid() === -1) {
Process::signal(SIGTERM | SIGKILL, function ($signo) use ($process) {
if ($signo) {
$lists = Kiri::app()->getProcess();
foreach ($lists as $process) {
$process->exit(0);
}
}
});
} else {
go(function () use ($process) {
$data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1);
if ($data) {
$this->onProcessStop();
$this->waiteExit($process);
$lists = Kiri::app()->getProcess();
foreach ($lists as $process) {
$process->exit(0);
}
}
});
}