h4kuna / queue
System V message queue in php.
v0.1.6
2023-09-27 11:09 UTC
Requires
- php: >=8.0
- ext-sysvmsg: *
- h4kuna/data-type: ^3.0
- h4kuna/dir: ^0.1.3
- h4kuna/memoize: ^0.1
- mll-lab/str_putcsv: ^1.1
Requires (Dev)
- h4kuna/serialize-polyfill: ^0.2.2
- nette/tester: ^2.3
- phpstan/phpstan: ^1.9
- phpstan/phpstan-strict-rules: ^1.4
- tracy/tracy: ^2.7
Suggests
- ext-inotify: For passive waiting, if you want to use SystemF.
- ext-lib: For compress messages, lobger then 150 chars.
- ext-sysvmsg: For php native msg_* functions aka SystemV.
This package is auto-updated.
Last update: 2024-10-30 01:37:18 UTC
README
This use native php queue msg_* functions.
Installation by composer
composer require h4kuna/queue
How to use
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'
Limitations
This is not server, it can run as only instance on current computer.
Catch receive error
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);
List of queues
ipcs -q
Error codes for receive: