php fpm queue
0.1.2: Merge pull request #4 from sunkan
Verwenden Sie PHP-FPM als einfache eingebaute asynchrische Warteschlange. Basierend auf interoperablen Warteschlangenqueue -Warteschlangeninterop.
composer makasim/php-fpm-queue:0.1.x-dev queue-interop/queue-interop:0.7.x-dev enqueue/dsn:0.9.x-devEin Absendungsskript:
<?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 );Ein Arbeitskript:
<?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 );
}Starten Sie PHP-FPM:
docker run -v ` pwd ` :/app -p 9000:9000 php:7.2-fpmSenden Sie eine Nachricht:
php sender.phpInspiriert von Benjamin Post mit PHP-FPM als einfache integrierte asynchronisierte Warteschlange
MIT -Lizenz