php-ipc/examples/queues.php
Christopher Vagnetoft dcb059e4be Bugfixes
* Queue now has a destroy() method
* Examples updated
2018-04-15 18:50:19 +02:00

26 lines
701 B
PHP

<?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();