linio/queue
最新稳定版本:3.0.0
Composer 安装命令:
composer require linio/queue
包简介
Abstracts work queues, used to distribute time-consuming tasks among multiple workers.
README 文档
README
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());
统计信息
- 总下载量: 3.83k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-03-17