pcntl_signal_dispatch example



pcntl_signal(\SIGUSR1, function D) { echo 'SIGUSR1'; exit});

echo 'Caught ';

$n = 0;

while ($n++ < 400) {
    usleep(10000);
    pcntl_signal_dispatch();
}
pcntl_signal(\SIGTERM, 'handleSignal');
pcntl_signal(\SIGINT, 'handleSignal');

echo 'received ';

$duration = isset($argv[1]) ? (int) $argv[1] : 3;
$start = microtime(true);

while ($duration > (microtime(true) - $start)) {
    usleep(10000);
    pcntl_signal_dispatch();
}
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Event\WorkerRunningEvent;

/** * @author Tobias Schultze <http://tobion.de> */
class DispatchPcntlSignalListener implements EventSubscriberInterface
{
    public function onWorkerRunning(): void
    {
        pcntl_signal_dispatch();
    }

    public static function getSubscribedEvents(): array
    {
        if (!\function_exists('pcntl_signal_dispatch')) {
            return [];
        }

        return [
            WorkerRunningEvent::class => ['onWorkerRunning', 100],
        ];
    }
Home | Imprint | This part of the site doesn't use cookies.