Skip to content

Innmind/Signals

Repository files navigation

Signals

Build Status codecov Type Coverage

Small abstraction on top of pcntl_signal to allow to register multiple callables for a single signal.

Installation

composer require innmind/signals

Usage

use Innmind\Signals\{
    Handler,
    Signal,
    Info,
};

$handler = Handler::main(); // automatically enable async signal on first `->listen()` call

$handler->listen(Signal::interrupt, function(Signal $signal, Info $info): void {
    echo 'foo';
});
$handler->listen(Signal::interrupt, function(Signal $signal, Info $info): void {
    echo 'bar';
});

// do some logic here

When above script is executed in a terminal and you do a ctrl + c to stop the process it will print foobar instead of stopping the script.

If for some reason you need to remove a handler (for example when a child process ended) you can call $handler->remove($listener) (remove the listener for all signals).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages