Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
```