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

34
examples/shmdata.php Normal file
View File

@ -0,0 +1,34 @@
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\Ipc\Shm\SharedData;
use NoccyLabs\Ipc\Key\FileKey;
$key = new FileKey(__FILE__);
$shm = new SharedData($key);
// Set works as expected
$shm->set("some.key", "Some value");
// As does get
echo $shm->get("some.key")."\n";
// To make sure a value isn't modified while you are modifying it, use the third
// parameter to set...
//
// Let's start at 123
$shm->set("some.counter", 123);
$counter = $shm->get("some.counter");
echo "Counter is: ".$counter."\n";
// And attempt to increase it
$shm->set("some.counter", $counter + 1, true);
$counter = $shm->get("some.counter");
echo "Counter is: ".$counter."\n";
// If the value is modified, the call will fail
$shm2 = new SharedData($key);
$shm2->set("some.counter", 345);
if (!$shm->set("some.counter", $counter + 1, true)) {
echo "some.counter has been modified since last read\n";
}