makasim / php-fpm-queue
Use php-fpm as a simple built-in async queue
Installs: 109
Dependents: 0
Suggesters: 0
Security: 0
Stars: 115
Watchers: 4
Forks: 3
Open Issues: 3
Requires
- php: ^7.1.3
- enqueue/dsn: ^0.9
- hollodotme/fast-cgi-client: ^2
- queue-interop/queue-interop: ^0.7
This package is auto-updated.
Last update: 2024-11-29 05:21:15 UTC
README
Use php-fpm as a simple built-in async queue. Based on interoperable queue interfaces Queue Interop.
Usage
composer makasim/php-fpm-queue:0.1.x-dev queue-interop/queue-interop:0.7.x-dev enqueue/dsn:0.9.x-dev
A sender script:
<?php # sender.php use Makasim\PhpFpm\PhpFpmConnectionFactory; require_once __DIR__.'/vendor/autoload.php'; $context = (new PhpFpmConnectionFactory('tcp://localhost:9000'))->createContext(); $queue = $context->createQueue('/app/worker.php'); $message = $context->createMessage('aBody'); $context->createProducer()->send($queue, $message);
A worker script:
<?php # worker.php use Makasim\PhpFpm\PhpFpmConnectionFactory; require_once __DIR__.'/vendor/autoload.php'; $context = (new PhpFpmConnectionFactory('tcp://localhost:9000'))->createContext(); // or //$context = (new PhpFpmConnectionFactory('unix:///var/run/php/php7.1-fpm.sock'))->createContext(); $queue = $context->createQueue(__FILE__); $consumer = $context->createConsumer($queue); if ($message = $consumer->receiveNoWait()) { // process message $consumer->acknowledge($message); }
Start PHP-FPM:
docker run -v `pwd`:/app -p 9000:9000 php:7.2-fpm
Send a message:
php sender.php
Credits
Inspired by Benjamin post Using php-fpm as a simple built-in async queue