1

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

});

Andrey Lebedev
  • 141
  • 1
  • 9

1 Answers1

0

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.

Fakhar Anwar
  • 295
  • 1
  • 3
  • 20