Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rstgroup/php-signal-handler
Singnal handling based on C signal for blocking/nonblocking php scripts
https://github.com/rstgroup/php-signal-handler
Last synced: about 2 months ago
JSON representation
Singnal handling based on C signal for blocking/nonblocking php scripts
- Host: GitHub
- URL: https://github.com/rstgroup/php-signal-handler
- Owner: rstgroup
- License: other
- Created: 2014-02-18T11:46:33.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-07-05T14:46:48.000Z (over 2 years ago)
- Last Synced: 2024-04-13T19:29:39.905Z (9 months ago)
- Language: C
- Homepage:
- Size: 23.4 KB
- Stars: 58
- Watchers: 20
- Forks: 15
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP Signal Handler
====================
[![Build Status](https://travis-ci.org/rstgroup/php-signal-handler.png?branch=master)](https://travis-ci.org/rstgroup/php-signal-handler)Extension uses C signal function (from ) to call previously defined callback, if appropriate signal has arrived (i.e SIGUSR1).
### When should I use it?
Could be used with [php-amqp](https://github.com/pdezwart/php-amqp) to print the actual worker/consumer status (ie. message stats, last operation performed etc.)
What's more it is possible to "catch" a unix signal i.e. SIGTERM and then kill the process nicely (program won't stop untill all operations are completed). It is very useful if script operates on sensitive data which cannot be damaged.### Why don't you use pcntl_signal?
If a blocking method (such as ```AMQPQueue::consume()``` from [php-amqp](https://github.com/pdezwart/php-amqp)) is holding the processing thread, then you won't be able to call [pcntl_signal_dispatch()](http://php.net/manual/en/function.pcntl-signal-dispatch.php) and trigger the callbacks registered with [pcntl_signal()](http://php.net/manual/en/function.pcntl-signal.php).### Compatibility
Extension will work only if C function ```signal``` is available (only on UNIX systems).
PHP versions supported:
* PHP 7
* PHP 5.6
* PHP 5.5
* PHP 5.4
* PHP 5.3### Example
```php```
Spawn the process:
```
php your_script_name.php
```Kill the first process from the list:
```
kill -s SIGUSR1 `ps -ef | grep php | head -n1 | awk '{print $2}'`
```After that steps you should see:
```
getInfo called with status 10
```