funddy/worker

Worker component

Installs: 1 345

Dependents: 0

Stars: 9

Watchers: 3

Language: PHP

v2.0.0 2013-03-07 02:12 UTC

README

Build Status

Simple asynchronous worker library based on Redis queues.

Setup and Configuration

Add the following to your composer.json file:

{
    "require": {
        "funddy/worker": "2.0.*"
    }
}

Update the vendor libraries:

curl -s http://getcomposer.org/installer | php
php composer.phar install

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;
}