jiromm/react-signal-handler

Unix signals handling for ReactPHP

v1.2.0 2018-12-14 07:40 UTC

This package is auto-updated.

Last update: 2024-04-14 20:14:18 UTC


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();