crunch/signal

This package is abandoned and no longer maintained. No replacement package was suggested.

process signal handling

dev-master / 1.0.x-dev 2014-04-24 22:24 UTC

This package is not auto-updated.

Last update: 2024-01-11 01:23:23 UTC


README

Simple process signal wrapper

Requirements

  • PHP => 5.4
  • ext-pcntl => *

Also ensure, that the pcntl_*() are not disabled via disabled_functions php.ini-setting.

Usage

Waits ten seconds for a SIGTERM-signal.

use Crunch\Signal;

Signal\wait([Signal\TERM], function (Signal\Info $info) {
    // Do something useful
}, 10);

Postpone certain signals

use Crunch\Signal;

$oldMask = Signal\block([Signal\TERM, Signal\HUP]);
// Some critical stuff
Signal\reset($oldMask);

A simple timer

use Crunch\Signal;

Signal\Timer(5);
Signal\wait([Signal\TERM, Signal\ALRM], function (Signal\Info $info) {
    // Do something useful
}, 10);

Register a signal handler. declare(ticks=x) is required.

declare(ticks=1);
use Crunch\Signal;

require __DIR__ . '/../vendor/autoload.php';


echo posix_getpid() . PHP_EOL;
Signal\register(Signal\USR1, function (Signal\Info $info) { echo "USR1!"; exit; });

while (true) {
    // very busy code
}

Contributors

See CONTRIBUTING.md for details on how to contribute.

License

This library is licensed under the MIT License. See the LICENSE file for details.