Handle process signals in Swoole script without pcntl_signal() function

416 views Asked by At

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;
        }
    }

});

1

There are 1 answers

0
Fakhar Anwar On

Swoole Process Signal

Main-page to Swoole Process

Please also explore Swoole Process Manager, and binding process with Swoole Server using addServer(), and Swoole Process Daemon.