Bugfixes
* Queue now has a destroy() method * Examples updated
This commit is contained in:
parent
4e8ab73a88
commit
dcb059e4be
26
examples/queues.php
Normal file
26
examples/queues.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__."/../vendor/autoload.php";
|
||||||
|
|
||||||
|
use NoccyLabs\Ipc\Key\FileKey;
|
||||||
|
use NoccyLabs\Ipc\Msg\Queue;
|
||||||
|
|
||||||
|
$key = new FileKey(__FILE__);
|
||||||
|
$msgq = new Queue($key);
|
||||||
|
|
||||||
|
// Send packages with msgtype >= 1...
|
||||||
|
$msgq->send(1, [ "what"=>"First" ]);
|
||||||
|
$msgq->send(2, [ "what"=>"Second" ]);
|
||||||
|
$msgq->send(3, [ "what"=>"Third" ]);
|
||||||
|
|
||||||
|
// Read messages by requesting a type...
|
||||||
|
$msg = $msgq->receive(2, $type);
|
||||||
|
printf("msg: %s, type: %d\n", json_encode($msg), $type);
|
||||||
|
|
||||||
|
// ...or read the first message with type 0...
|
||||||
|
$msg = $msgq->receive(0, $type);
|
||||||
|
printf("msg: %s, type: %d\n", json_encode($msg), $type);
|
||||||
|
$msg = $msgq->receive(0, $type);
|
||||||
|
printf("msg: %s, type: %d\n", json_encode($msg), $type);
|
||||||
|
|
||||||
|
$msgq->destroy();
|
@ -32,3 +32,4 @@ if (!$shm->set("some.counter", $counter + 1, true)) {
|
|||||||
echo "some.counter has been modified since last read\n";
|
echo "some.counter has been modified since last read\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$shm->destroy();
|
@ -32,6 +32,13 @@ class Queue
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function destroy()
|
||||||
|
{
|
||||||
|
if ($this->resource) {
|
||||||
|
msg_remove_queue($this->resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send to the queue
|
* Send to the queue
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user