kafkiansky / signaler
Signaler library that provide stack for signal listeners.
v0.1.0
2022-03-24 10:22 UTC
Requires
- php: >=7.4
- ext-pcntl: *
- psr/log: ^1.1
- seld/signal-handler: ^1.3
Requires (Dev)
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.22
This package is auto-updated.
Last update: 2024-11-24 15:56:23 UTC
README
Contents
Installation
composer require kafkiansky/signaler
Usage
Simple example with \SIGINT
signal.
use Kafkiansky\Signaler\SeldSignalFactory; use Psr\Log\NullLogger; $factory = new SeldSignalFactory(new NullLogger()); $signaler = $factory->subscribe([ \SIGINT => function () use ($worker): void { $worker->stop(); } ]); while ($signaler->isTriggered() === false) { // }
The main purpose of this library is to prevent the signal listener from being replaced by the pcntl_signal
function if it was previously configured by vendor code.
The library carefully saves previous signal listeners and will call them after yours.
In e.g.:
use Kafkiansky\Signaler\SeldSignalFactory; use Psr\Log\NullLogger; pcntl_signal(\SIGINT, function (): void { // This function will still be called after all your listeners. }); $factory = new SeldSignalFactory(new NullLogger()); $signaler = $factory->subscribe([ \SIGINT => function () use ($worker): void { $worker->stop(); } ]); while ($signaler->isTriggered() === false) { // }
Testing
$ composer test
License
The MIT License (MIT). See License File for more information.