jiromm / react-signal-handler
Unix signals handling for ReactPHP
v1.2.0
2018-12-14 07:40 UTC
Requires
- php: ^7.0
- ext-pcntl: *
- evenement/evenement: ^3.0
- react/event-loop: ^0.5
README
Unix signals handler for React PHP.
Install
The best way to install this library is through composer:
$ composer require jiromm/react-signal-handler
Usage
<?php require __DIR__ . '/../vendor/autoload.php'; $loop = \React\EventLoop\Factory::create(); $killer = new React\Signals\Killer\SerialKiller($loop, [SIGTERM, SIGINT]); $loop->addPeriodicTimer(1, function () { echo '.'; }); $killer->onExit(function ($signo, $errno, $code) use ($loop) { echo sprintf('[%s] signal received. Waiting 5 seconds.', $signo) . PHP_EOL; // ... // Do some important stuff // ... shell_exec('exec sleep 5s'); $loop->stop(); }); $loop->run();