I'm implementing a php parallel tasks script based on Swoole module which works as daemon.
Is it possible to use Swoole functions to handle process signals instead of pcntl_signal()?
<?php
declare(strict_types=1);
declare(ticks=1);
use Swoole\Coroutine as Co;
$stopCommand = false;
$sigHandler = static function (int $sig) use (&$stopCommand)
{
switch ($sig) {
case SIGTERM:
$stopCommand = true;
break;
}
};
pcntl_signal(SIGTERM, $sigHandler);
Co\run(function() use (&$stopCommand) {
$results = [];
while(true) {
//go(static function () use (&$results, &$stopCommand) {}
co::sleep(1);
if(!$results && $stopCommand) {
break;
}
}
});