gglinux / yii2-queue

Yii2 Queue Extension which supported DB, Redis, RabbitMQ and Gearman

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yii2 Queue Extension

Extension for async execution of jobs through a queue mechanism.

It supported queues based on DB, Redis, RabbitMQ, Beanstalk and Gearman.

Documentation is at docs/guide/README.md.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist zhuravljov/yii2-queue

or add

"zhuravljov/yii2-queue": "*"

to the require section of your composer.json file.

Basic Usage

Job class example:

class DownloadJob extends Object implements \zhuravljov\yii\queue\Job
{
    public $url;
    public $file;
    
    public function run()
    {
        file_put_contents($this->file, file_get_contents($this->url));
    }
}

Pushes job into queue:

Yii::$app->queue->push(new DownloadJob([
    'url' => 'http://example.com/image.jpg',
    'file' => '/tmp/image.jpg',
]));

Method of handling a queue depend on selected driver.

Pushes job into queue that run after 5 min:

Yii::$app->queue->later(new DownloadJob([
    'url' => 'http://example.com/image.jpg',
    'file' => '/tmp/image.jpg',
]), 5 * 60);

But only some drivers support delayed running.

For more details see the guide.

About

Yii2 Queue Extension which supported DB, Redis, RabbitMQ and Gearman

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:PHP 100.0%