funddy/worker

v3.0.0 2015-09-12 13:07 UTC

README

Build Status

Simple asynchronous worker library based on Redis queues.

Installation

composer require funddy/worker

Usage

Publisher

<?php

require 'vendor/autoload.php';

use Funddy\Worker\WorkerRedisClient\PredisWorkerRedisClient;
use Funddy\Worker\WorkQueue\RedisWorkQueue;
use Predis\Client;

$predisClient = new Client('tcp://localhost');
$redisClient = new PredisWorkerRedisClient($predisClient);
$queue = new RedisWorkQueue('myqueue', $redisClient);

$queue->publish('Hello world!');

Consumer

<?php

require 'vendor/autoload.php';

use Funddy\Worker\WorkerRedisClient\PredisWorkerRedisClient;
use Funddy\Worker\WorkQueue\RedisWorkQueue;
use Predis\Client;

$predisClient = new Client('tcp://localhost');
$redisClient = new PredisWorkerRedisClient($predisClient);
$queue = new RedisWorkQueue('myqueue', $redisClient);

while(true) {
    $message = $queue->consume();//Blocking
    echo $message;
}