Skip to content

Repository files navigation

Linio Queue

Latest Stable VersionLicenseBuild StatusScrutinizer 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:

<?phpuseLinio\Component\Queue\QueueService;
useLinio\Component\Queue\Adapter;
$queue = newQueueService();
$queue->setAdapter(newAdapter\RabbitAdapter([
'host' => 'localhost',
'port' => 5672,
'username' => 'guest',
'password' => 'guest',
'vhost' => '/'
]));

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

<?phpuseLinio\Component\Queue\Job;
class HelloWorldJob extends Job
{
publicfunctionperform()
{
echosprintf("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:

<?phpuseLinio\Component\Queue\QueueService;
$queue = newQueueService();
$queue->add(newHelloWorldJob('John')); // "John" is the payload

And to consume messages from the work queue:

<?phpuseLinio\Component\Queue\QueueService;
$queue = newQueueService();
$queue->perform(newHelloWorldJob());

About

Abstracts work queues, used to distribute time-consuming tasks among multiple workers.

Resources

Stars

3 stars

Watchers

53 watching

Forks

Releases

Packages

Used by

Contributors

Languages