Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stavarengo/php-signal-handler
Library that helps you handle signals from your operational system. It will help you, for example, to detect when some other process ask your script to stop.
https://github.com/stavarengo/php-signal-handler
Last synced: 2 months ago
JSON representation
Library that helps you handle signals from your operational system. It will help you, for example, to detect when some other process ask your script to stop.
- Host: GitHub
- URL: https://github.com/stavarengo/php-signal-handler
- Owner: stavarengo
- Created: 2016-11-27T23:10:29.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-27T21:03:44.000Z (over 6 years ago)
- Last Synced: 2024-04-20T05:02:34.363Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# php-signal-handler
A new and taste way to handle signal from your operational system.
If you need to detect when some other process ask your script to stop, this is the library you are looking for.Internally We use [pcntl-signal](http://php.net/manual/en/function.pcntl-signal.php) PHP function, so, if you wanna to create your own code to detect this signals, read the docs of this function is a good start.
## Installing
Execute `composer require stavarengo/php-signal-handler`
## How to use it
We use the observer patner to notify listeners when the signal it wants to listen arrives.So, first you need to implement the interface `\Sta\PhpSignalHandler\Listener`.
After that, just call `\Sta\PhpSignalHandler\SignalHandler::attach(array(SIGTERM), $listener)`, where:
1. `SIGTERM` is one of the constants about signals that PHP offers to us ([see here](http://php.net/manual/en/function.pcntl-signal.php)).
2. You will only notified about the signals you passed as the first parameter, in the example above, only the signal `SIGTERM`.
2. `$listener` is an instance of a class that implements the interface `\Sta\PhpSignalHandler\Listener`.Thats all! When your script receive a signal that you are interested, the listener will be notified.