This use native php queue msg_* functions.
composer require h4kuna/queue
Base is QueueFactory.
use h4kuna\Queue;
/** @var Queue\QueueFactory $queue */
$queueFactory = new Queue\QueueFactory();
/** @var Queue\Queue $queue */
$queue = $queueFactory->create('my-queue');
$queue->producer()->send('Hello');
$queue->consumer()->receive()->message === 'Hello'
The messages can to have different types.
$queue->producer()->send('Hello', 2);
$queue->consumer()->tryReceive() === NULL // non blocking read
$queue->consumer()->receive(2)->message === 'Hello'
Or read all types
$queue->producer()->send('Hello', 2);
$queue->consumer()->receive(Queue\Config::TYPE_ALL)->message === 'Hello'
This is not server, it can run as only instance on current computer.
The queue has backup implementation by Backup.
use h4kuna\Queue;
/** @var Queue\QueueFactory $queue */
$queueFactory = new Queue\QueueFactory();
/** @var Queue\Queue $queue */
$queue = $queueFactory->create('my-queue');
$queue->restore(); // restore from backup, after restart
do {
try {
$message = $queue->consumer()->receive();
// ...
} catch (Queue\ReceiveException $e) {
// log error
// stop process if code is 22
}
} while(true);
ipcs -q
Error codes for receive: