Stack Signaler.
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.