diff --git a/examples/queues.php b/examples/queues.php new file mode 100644 index 0000000..2704807 --- /dev/null +++ b/examples/queues.php @@ -0,0 +1,26 @@ += 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(); \ No newline at end of file diff --git a/examples/shmdata.php b/examples/shmdata.php index 289dde3..1da5923 100644 --- a/examples/shmdata.php +++ b/examples/shmdata.php @@ -32,3 +32,4 @@ if (!$shm->set("some.counter", $counter + 1, true)) { echo "some.counter has been modified since last read\n"; } +$shm->destroy(); \ No newline at end of file diff --git a/src/Msg/Queue.php b/src/Msg/Queue.php index 078e365..568accc 100644 --- a/src/Msg/Queue.php +++ b/src/Msg/Queue.php @@ -32,6 +32,13 @@ class Queue } + public function destroy() + { + if ($this->resource) { + msg_remove_queue($this->resource); + } + } + /** * Send to the queue *