neutron / signal-handler
A library to ease the use of signal handling.
Installs: 99 244
Dependents: 1
Suggesters: 0
Security: 0
Stars: 12
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.3
Requires (Dev)
- phpunit/phpunit: ~3.7
This package is auto-updated.
Last update: 2024-10-25 07:05:37 UTC
README
A simple signal handler to manage incoming posix signals.
It is implemented as a singleton as pcntl_signal
can only register one
callback per signal.
Using this one, you can register as many callbacks per signal as needed.
For more information about signals, man signal
.
// mandatory to listen to signals declare(ticks=1); $handler = Neutron\SignalHandler\SignalHandler::getInstance(); $handler->register(array(SIGINT, SIGTERM), function () { echo "stoppin !"; exit(); }); $handler->register(SIGCONT, function () { echo "all systems go..."; });
Register a signal handler
// register a handler for SIGCONT in default namespace $handler->register(SIGCONT, function () { echo "SIGCONT received"; }); // register a handler for SIGCONT in "a namespace" $handler->register(SIGCONT, function () { echo "SIGCONT received"; }, 'a namespace'); // register a handler for SIGCONT in "another namespace" $handler->register(SIGINT, function () { echo "Interrupted !"; exit(); }, 'another namespace');
Unregister signals handler
Two ways are available to unregister signals.
By namespace :
// unregister all handlers in "another namespace" $handler->unregisterNamespace('another namespace'); // unregister all SIGINT handlers in "a namespace" $handler->unregisterNamespace('a namespace', SIGINT);
By signal :
// unregister all SIGINT handlers in any namespace $handler->unregisterSignal(SIGINT);
License
This project is released under the MIT license.