dev-master
9999999-devPHP queue platform to simple build queue job
MIT
The Requires
- php ^7.1
- ext-json *
The Development Requires
PHP queue platform to simple build queue job
PHP Queue Platform provides an easy way to build queue system in PHP., (*2)
The easiest path to use queue platform is to use QueuePlatformExample repository., (*3)
QueuePlatformExample provides a complete working example with sample workers.
To run and test it, it comes with configured vagrant setup. To use it just boot up vagrant with vagrant up
., (*4)
Vagrant setup will set up a complete environment. It will start 5 working processes, setup queue manager URL and server testing GUI., (*5)
URL to testing GUI: http://192.168.29.6/index.html, (*6)
How to modify it, see docs in QueuePlatformExample repository., (*7)
Require QueuePlatform package with composer: composer require bostjanob/queue-platform
., (*8)
Workers must extend BostjanOb\QueuePlatform\Worker
interface., (*9)
The only method to implement is run($params = null)
., (*10)
Create a new BostjanOb\QueuePlatform\QueueManager
object and register your workers with it., (*11)
For constructor, you must provide storage object (object that implements \BostjanOb\QueuePlatform\Storage\Storage
), (*12)
<?php // queuemanager.php $storage = new \BostjanOb\QueuePlatform\Storage\SqlLiteStorage('db.sqlite3'); $qm = new \BostjanOb\QueuePlatform\QueueManager($storage); $qm->registerWorker('task-name', new Worker());
To push task, get task status and to make communication with working processes QueueManager uses JSON-RPC. So it must be accessible by a web server (over URL)., (*13)
To listen for json-rpc request run listen()
on QueueManager., (*14)
<?php // queue.php - server over web server require 'queuemanager.php'; echo $qm->listen();
To start long running working process call work()
on QueueManager. Run it from CLI and pass URL to QueueManager (in step 4) as a parameter., (*15)
<?php // process.php require 'queuemanager.php'; $qm->work();
Run from CLI:, (*16)
php process.php http://example.com/queue.php
QueueManager JSON-RPC provides two methods to interact with., (*17)
Queue task to be then later pulled by the processor. It accepts one or two parameters., (*18)
the first parameter is the name of a worker registered with a queue manager, (*19)
the second parameter is a parameter for the worker. It accepts a single value. If you want to pass multiple values use an array., (*20)
returned result is a task object as a JSON-RPC result, (*21)
getTask method return task object. The method requires id of a task as a first parameter., (*22)
To run long running process run PHP script from CLI (step 5.)., (*23)
Command to start process:, (*24)
php file.php [OPTIONS] URL_TO_QUEUEMANAGER
Available options: - workers - List workers to work with. Default to all registered in QueueManage. (split by comma) - sleep - How many seconds to wait if there is no task. The process will check if there is some task and if there is none it will wait before checking again., (*25)
Example with options:, (*26)
php file.php --workers=foo,bar --sleep=3 http://example.com/queue.php
PHP queue platform to simple build queue job
MIT