More examples and tweaks

* Signal dispatch() method now uses own pid as default value
* SharedData now updates checksum cache on set()
This commit is contained in:
2018-04-15 17:25:55 +02:00
parent 86ff40274b
commit 176f9aa5ec
8 changed files with 148 additions and 3 deletions

29
examples/signals.php Normal file
View File

@ -0,0 +1,29 @@
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\Ipc\Signal\SignalHandler;
use NoccyLabs\Ipc\Signal\Signal;
$handler = new SignalHandler(SIGUSR1);
// Add handlers like this, or as an array passed as the second argument to the constructor
$handler->addHandler(function () {
echo "First handler\n";
});
// If a handler returns true, it will prevent any further handlers from firing
$handler->addHandler(function () {
echo "Second and final handler\n";
return true;
});
// Thus, this one will not be called
$handler->addHandler(function() {
echo "Third handler, never called\n";
});
// Dispatch the signal to ourselves
(new Signal(SIGUSR1))->dispatch(posix_getpid());
// Default target of dispatch is the own pid
(new Signal(SIGUSR1))->dispatch();