innmind/signals
Composer 安装命令:
composer require innmind/signals
包简介
Manage multiple callbacks per signal
README 文档
README
Small abstraction on top of pcntl_signal to allow to register multiple callables for a single signal.
Installation
composer require innmind/signals
Usage
use Innmind\Signals\{ Handler, Signal, Info, }; $handler = Handler::main(); // automatically enable async signal on first `->listen()` call $handler ->listen(Signal::interrupt, function(Signal $signal, Info $info): void { echo 'foo'; }) ->unwrap(); $handler ->listen(Signal::interrupt, function(Signal $signal, Info $info): void { echo 'bar'; }) ->unwrap(); // do some logic here
When above script is executed in a terminal and you do a ctrl + c to stop the process it will print foobar instead of stopping the script.
If for some reason you need to remove a handler (for example when a child process ended) you can call $handler->remove($listener)->unwrap() (remove the listener for all signals).
统计信息
- 总下载量: 102.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-25