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 <b>signal</b> function (from <signal.h>) to call previously defined callback, if appropriate signal has arrived (i.e SIGUSR1).
### When should I use it?
Could be used with <b>[php-amqp](https://github.com/pdezwart/php-amqp)</b> to print the actual worker/consumer status (ie. message stats, last operation performed etc.) <br />
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 <i>[pcntl_signal_dispatch()](http://php.net/manual/en/function.pcntl-signal-dispatch.php)</i> and trigger the callbacks registered with <i>[pcntl_signal()](http://php.net/manual/en/function.pcntl-signal.php)</i>.
### Compatibility
Extension will work only if C function ```signal``` is available (only on UNIX systems).<br/>
PHP versions supported: <br/>
* PHP 7
* PHP 5.6
* PHP 5.5
* PHP 5.4
* PHP 5.3
### Example
```php
<?php
function getInfo($noStatus){
echo "getInfo called with status $noStatus\n";
}
$r = attach_signal(10, 'getInfo');
while(true){}
?>
```
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
```
没有合适的资源?快使用搜索试试~ 我知道了~
基于C信号的信号处理,用于阻塞非阻塞php脚本_C_PHP_下载.zip
共14个文件
phpt:4个
yml:1个
h:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 14 浏览量
2023-04-26
11:37:07
上传
评论
收藏 11KB ZIP 举报
温馨提示
基于C信号的信号处理,用于阻塞非阻塞php脚本_C_PHP_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于C信号的信号处理,用于阻塞非阻塞php脚本_C_PHP_下载.zip (14个子文件)
php-signal-handler-master
config.m4 2KB
.travis.yml 268B
signal_handler.c 7KB
LICENCE 3KB
tests
attach_signal_error.phpt 821B
attach_signal_basic.phpt 580B
detach_signal_basic.phpt 567B
detach_signal_error.phpt 703B
signal_handler.php 526B
test-report.sh 225B
config.w32 352B
php_signal_handler.h 2KB
CREDITS 142B
README.md 2KB
共 14 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功