yiisoft/yii2-queue Yii2 Queue Extension which supported DB, Redis, RabbitMQ, Beanstalk, SQS and Gearman



Yii2 Queue Extension

An extension for running tasks asynchronously via queues.

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

Documentation is at https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/README.md.

Latest Stable Version Total Downloads Build Status


The preferred way to install this extension is through composer.

Either run

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

or add

"yiisoft/yii2-queue": "~2.0"

to the require section of your composer.json file.

Basic Usage

Each task which is sent to queue should be defined as a separate class. For example, if you need to download and save a file the class may look like the following:

class DownloadJob extends BaseObject implements \yii\queue\JobInterface
    public $url;
    public $file;

    public function execute($queue)
        file_put_contents($this->file, file_get_contents($this->url));

Here's how to send a task into the queue:

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

To push a job into the queue that should run after 5 minutes:

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

The exact way a task is executed depends on the used driver. Most drivers can be run using console commands, which the component automatically registers in your application.

This command obtains and executes tasks in a loop until the queue is empty:

yii queue/run

This command launches a daemon which infinitely queries the queue:

yii queue/listen

See the documentation for more details about driver specific console commands and their options.

The component also has the ability to track the status of a job which was pushed into queue.

// Push a job into the queue and get a message ID.
$id = Yii::$app->queue->push(new SomeJob());

// Check whether the job is waiting for execution.

// Check whether a worker got the job from the queue and executes it.

// Check whether a worker has executed the job.

For more details see the guide.


Yii2 Queue Extension Change Log

2.1.1 under development

  • Enh #248: Reduce roundtrips to beanstalk server when removing job (SamMousa)
  • Bug #258: Worker in isolated mode fails if PHP_BINARY contains spaces (luke-)
  • Bug #269: Handling of broken messages that are not unserialized correctly (zhuravljov)
  • Bug #267: Fixed symfony/process incompatibility (rob006)
  • Enh: Job execution result that forwarded to the event handler (zhuravljov)
  • Enh: ErrorEvent mark as deprecated (zhuravljov)

2.1.0 May 24, 2018

  • Bug #210: Worker option to define php bin path to run child process (zhuravljov)
  • Enh: Worker loop event (zhuravljov)
  • Bug #207: Console params validation (zhuravljov)
  • Bug #224: Invalid identifier "DELAY" (lar-dragon)
  • Enh #192: AWS SQS implementation (elitemaks, manoj-girnar)
  • Bug #126: Handles a fatal error of the job execution in isolate mode (zhuravljov)

2.0.2 December 26, 2017

  • Bug #92: Resolve issue in debug panel (farmani-eigital)
  • Bug #99: Retry connecting after connection has timed out for redis driver (cebe)
  • Bug #180: Fixed info command of file driver (victorruan)
  • Enh #158: Add Amqp Interop driver (makasim)
  • Enh #185: Loop object instead of Signal helper (zhuravljov)
  • Enh #188: Configurable verbose mode (zhuravljov)
  • Enh: Start and stop events of a worker (zhuravljov)

2.0.1 November 13, 2017

  • Bug #98: Fixed timeout error handler (zhuravljov)
  • Bug #112: Queue command inside module (tsingsun)
  • Bug #118: Synchronized moving of delayed and reserved jobs to waiting list (zhuravljov)
  • Bug #155: Slave DB breaks listener (zhuravljov)
  • Enh #97: Queue::status is public method (zhuravljov)
  • Enh #116: Add Chinese Guide (kids-return)
  • Enh #122: Rename Job to JobInterface (zhuravljov)
  • Enh #137: All throwable errors caused by jobs are now caught (brandonkelly)
  • Enh #141: Clear and remove commands for File, DB, Beanstalk and Redis drivers (zhuravljov)
  • Enh #147: Igbinary job serializer (xutl)
  • Enh #148: Allow to change vhost setting for RabbitMQ (ischenko)
  • Enh #151: Compatibility with Yii 2.0.13 and PHP 7.2 (zhuravljov)
  • Enh #160: Benchmark of job wait time (zhuravljov)
  • Enh: Rename cli\Verbose behavior to cli\VerboseBehavior (zhuravljov)
  • Enh: Rename serializers\Serializer interface to serializers\SerializerInterface (zhuravljov)
  • Enh: Added Signal::setExitFlag() to stop Queue::run() loop manually (silverfire)

2.0.0 July 15, 2017

  • Enh: The package is moved to yiisoft/yii2-queue (zhuravljov)

1.1.0 July 12, 2017

  • Enh #50 Documentation about worker starting control (zhuravljov)
  • Enh #70: Durability for rabbitmq queues (mkubenka)
  • Enh: Detailed error about job type in message handling (zhuravljov)
  • Enh #60: Enhanced event handling (zhuravljov)
  • Enh: Job priority for DB driver (zhuravljov)
  • Enh: File mode options of file driver (zhuravljov)
  • Enh #47: Redis queue listen timeout (zhuravljov)
  • Enh #23: Retryable jobs (zhuravljov)

1.0.1 June 7, 2017

  • Enh #58: Deleting failed jobs from queue (zhuravljov)
  • Enh #55: Job priority (zhuravljov)

1.0.0 May 4, 2017

  • Enh: Improvements of log behavior (zhuravljov)
  • Enh: File driver stat info (zhuravljov)
  • Enh: Beanstalk stat info (zhuravljov)
  • Enh: Colorized driver info actions (zhuravljov)
  • Enh: Colorized verbose mode (zhuravljov)
  • Enh: Improvements of debug panel (zhuravljov)
  • Enh: Queue job message statuses (zhuravljov)
  • Enh: Gii job generator (zhuravljov)
  • Enh: Enhanced gearman driver (zhuravljov)
  • Enh: Queue message identifiers (zhuravljov)
  • Enh: File queue (zhuravljov)

0.12.2 April 29, 2017

  • Enh #10: Separate option that turn off isolate mode of job execute (zhuravljov)

0.12.1 April 20, 2017

  • Bug #37: Fixed opening of a child process (zhuravljov)
  • Enh: Ability to push a closure (zhuravljov)
  • Enh: Before push event (zhuravljov)

0.12.0 April 14, 2017

  • Enh #18: Executes a job in a child process (zhuravljov)
  • Bug #25: Enabled output buffer breaks output streams (luke-)
  • Enh: After push event (zhuravljov)

0.11.0 April 2, 2017

  • Enh #21: Delayed jobs for redis queue (zhuravljov)
  • Enh: Info action for db and redis queue command (zhuravljov)

0.10.1 March 29, 2017

  • Bug: Fixed db driver for pgsql (zhuravljov)
  • Bug #16: Timeout of  queue reading lock for db driver (zhuravljov)
  • Enh: Minor code style enhancements (SilverFire)

0.10.0 March 22, 2017

  • Enh #14: Json job serializer (zhuravljov)
  • Enh: Delayed running of a job (zhuravljov)

0.9.1 March 6, 2017

  • Bug #13: Fixed reading of DB queue (zhuravljov)

0.9.0 March 6, 2017

  • Enh: Signal handlers (zhuravljov)
  • Enh: Add exchange for AMQP driver (airani)
  • Enh: Beanstalk driver (zhuravljov)
  • Enh: Added English docs (samdark)


GitHub Stars
GitHub Forks



2.1.0 is the latest of 28 releases

BSD-3-Clause license
777 github stars & 192 github forks
2005 downloads in the last day
46769 downloads in the last 30 days
458340 total downloads