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:
29
examples/signals.php
Normal file
29
examples/signals.php
Normal 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();
|
||||
|
Reference in New Issue
Block a user