Giter Club home page Giter Club logo

queue's Introduction

Linio Queue

Latest Stable Version License Build Status Scrutinizer Code Quality

Linio Queue abstracts work queues, used to distribute time-consuming tasks among multiple workers.

Install

The recommended way to install Linio Queue is through composer.

{
    "require": {
        "linio/queue": "~3.0"
    }
}

Tests

To run the test suite, you need install the dependencies via composer, then run PHPUnit.

$ composer install
$ phpunit

Usage

The library is very easy to use: first, you have to register the service. For Silex, a service provider is included. Just register it:

<?php

use Linio\Component\Queue\QueueService;
use Linio\Component\Queue\Adapter;

$queue = new QueueService();
$queue->setAdapter(new Adapter\RabbitAdapter([
    'host' => 'localhost',
    'port' => 5672,
    'username' => 'guest',
    'password' => 'guest',
    'vhost' => '/'
]));

In order to create a work queue, you must extend the abstract class Job:

<?php

use Linio\Component\Queue\Job;

class HelloWorldJob extends Job
{
    public function perform()
    {
        echo sprintf("Hello %s!\n", $this->payload);
        $this->finish();
    }
}

Note that you must always finish() a job to remove it from the queue. You can also fail() jobs. Now, in order to publish messages to a work queue:

<?php

use Linio\Component\Queue\QueueService;

$queue = new QueueService();
$queue->add(new HelloWorldJob('John')); // "John" is the payload

And to consume messages from the work queue:

<?php

use Linio\Component\Queue\QueueService;

$queue = new QueueService();
$queue->perform(new HelloWorldJob());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.