2017 © Pedro Peláez
 

library queue-platform

PHP queue platform to simple build queue job

image

bostjanob/queue-platform

PHP queue platform to simple build queue job

  • Wednesday, February 8, 2017
  • by BostjanOb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Queue Platform

Build Status, (*1)

PHP Queue Platform provides an easy way to build queue system in PHP., (*2)

Easy way

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)

Hard way

1. require package

Require QueuePlatform package with composer: composer require bostjanob/queue-platform., (*8)

2. create workers

Workers must extend BostjanOb\QueuePlatform\Worker interface., (*9)

The only method to implement is run($params = null)., (*10)

3. create QueueManager class and register workers

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());

4. make queue manager JSON-RPC public

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();

5. start working processes

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 SERVER

QueueManager JSON-RPC provides two methods to interact with., (*17)

- queueTask

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

getTask method return task object. The method requires id of a task as a first parameter., (*22)

QueueManager CLI working process

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
Options

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

The Versions

08/02 2017

dev-master

9999999-dev

PHP queue platform to simple build queue job

  Sources   Download

MIT

The Requires

  • php ^7.1
  • ext-json *

 

The Development Requires