PHPackages                             voodoo-mobile/yii2-queue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. voodoo-mobile/yii2-queue

AbandonedLibrary

voodoo-mobile/yii2-queue
========================

Queue component for Yii2

1.4.1(10y ago)02.0kMITPHPPHP &gt;=5.5.0

Since Apr 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/voodoo-mobile/yii2-queue)[ Packagist](https://packagist.org/packages/voodoo-mobile/yii2-queue)[ RSS](/packages/voodoo-mobile-yii2-queue/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (13)Versions (11)Used By (0)

Queue Component for Yii2
========================

[](#queue-component-for-yii2)

This provides queue component for Yii2.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist vm/yii2-queue "^1.4.0"

```

or add

```
"vm/yii2-queue": "^1.4.0"

```

to the require section of your `composer.json` file.

To use Redis queue or RabbitMQ, you have to add `yiisoft/yii2-redis:*` or `videlalvaro/php-amqplib: 2.5.*` respectively.

Setting Up
----------

[](#setting-up)

After the installation, first step is to set the console controller.

```
return [
    // ...
    'controllerMap' => [
        'queue' => [
            'class' => 'vm\queue\Console\Controller',
            //'sleepTimeout' => 1
        ],

    ],
];
```

For the task worker, set a new module, e.g. `task` and declare it in the config.

```
'modules' => [
    'task' => [
        'class' => 'app\modules\task\Module',
    ]
]
```

And then set the queue component. Don't forget to set the module name that runs the task in the component. For example, queue using AWS SQS

```
'components' => [
    'queue' => [
        'class' => 'vm\queue\Queues\SqsQueue',
        'module' => 'task',
        'url' => 'https://sqs.ap-southeast-1.amazonaws.com/123456789012/queue',
		'config' => [
			'key' => 'AKIA1234567890123456',
			'secret' => '1234567890123456789012345678901234567890',
			'region' => 'ap-southeast-1',
			'version' => 'latest'
        ],
    ]
]
```

Or using Database queue

```
'components' => [
    'db' => [
        //the db component
    ],
    'queue' => [
        'class' => 'vm\queue\Queues\DbQueue',
        'db' => 'db',
        'tableName' => 'queue',
        'module' => 'task',
    ]
]
```

Usage
-----

[](#usage)

### Creating A Worker

[](#creating-a-worker)

Creating a worker is just the same with creating console or web controller. In the task module create a controller that extends `vm\queue\Worker\Controller`

e.g.

```
class FooController extends vm\queue\Worker\Controller {

    public function actionBar($param1, $param2){
        echo $param1;
    }
}
```

To prevent the job got deleted from the queue, for example when the job is not completed, return `false` in the action. The job will be run again the next chance.

e.g.

```
class FooController extends vm\queue\Worker\Controller {

    public function actionBar($param1, $param2){
        try {
        } catch (\Exception $ex){
            \Yii::error('Ouch something just happened');
            return false;
        }
    }
}
```

### Running The Listener

[](#running-the-listener)

To run the listener, run the console that set in the above config. If the controller mapped as `queue` then run.

```
./yii queue/listen

```

### Posting A Job

[](#posting-a-job)

To post a job from source code, put something like this.

```
use vm\queue\Job;

$route = 'foo/bar';
$data = ['param1' => 'foo', 'param2' => 'bar'];
Yii::$app->queue->post(new Job(['route' => $route, 'data' => $data]));
```

Job can also be posted from the console. The data in the second parameter is in JSON string.

```
yii queue/post 'foo/bar' '{"param1": "foo", "param2": "bar"}'

```

Job can also be posted as anonymous function. Be careful using this.

```
Yii::$app->queue->post(new Job(function(){
    echo 'Hello World!';
}));
```

### Deferred Event

[](#deferred-event)

In this queue, there is a feature called **Deferred Event**. Basically using this feature, we can defer a process executed after a certain event using queue.

To use this, add behavior in a component and implement the defined event handler.

```
    public function behaviors() {
        return array_merge([
            [
                'class' => \vm\queue\Behaviors\DeferredEventBehavior::class,
                'events' => [
                    self::EVENT_AFTER_VALIDATE => 'deferAfterValidate',
                ]
            ]
        ]);
    }

    public function deferAfterValidate(){
        //Do something here.
    }
```

**NOTE**Due to reducing the message size, the `$event` object that usually passed when triggered the event will not be passed to the deferred event. Also, the object in which the method invoked is merely a clone object, so it won't have the behavior and the event attached in the original object.

As for `ActiveRecord` class, since the object can not be passed due to limitation of SuperClosure in serializing PDO (I personally think that's bad too), the behavior should use `\vm\queue\Behaviors\ActiveRecordDeferredEventBehavior`instead. The difference is in the object in which the deferred event handler invoked.

Since we can not pass the original object, the invoking object will be re-fetched from the table using the primary key. And for the `afterDelete` event, since the respective row is not in the table anymore, the invoking object is a new object whose attributes are assigned from the attributes of the original object.

### Web End Point

[](#web-end-point)

We can use web endpoint to use the queue by adding `\vm\queue\Web\Controller`to the controller map.

For example

```
    'controllerMap' => [
        'queue' => [
            /* @var $queue vm\queue\Web\Controller */
            'class' => 'vm\queue\Web\Controller'
        ]
    ],
```

To post this use

```
curl -XPOST http://example.com/queue/post --data route='test/test' --data data='{"data":"data"}'

```

To limit the access to the controller, we can use `\yii\filters\AccessControl` filter.

For example to filter by IP address, we can use something like this.

```
    'controllerMap' => [
        'queue' => [
            /* @var $queue vm\queue\Web\Controller */
            'class' => 'vm\queue\Web\Controller',
            'as access' => [
                'class' => '\yii\filters\AccessControl',
                'rules' => [
                    [
                        'allow' => true,
                        'ips' => [
                            '127.0.0.1'
                        ]
                    ]
                ]
            ]
        ]
    ],
```

Testing
-------

[](#testing)

To run the tests, in the root directory execute below.

```
./vendor/bin/phpunit

```

Road Map
--------

[](#road-map)

- Add more queue provider such as MemCache, IronMQ.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 87.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~79 days

Total

11

Last Release

3651d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/690fe9c695b36c27b53c0cf0f847579f7dc34d438eba2b42fc6f459e27253ef5?d=identicon)[voodoo-rocks](/maintainers/voodoo-rocks)

---

Top Contributors

[![petrabarus](https://avatars.githubusercontent.com/u/523289?v=4)](https://github.com/petrabarus "petrabarus (71 commits)")[![dieend](https://avatars.githubusercontent.com/u/1404443?v=4)](https://github.com/dieend "dieend (6 commits)")[![deerawan](https://avatars.githubusercontent.com/u/1243921?v=4)](https://github.com/deerawan "deerawan (3 commits)")[![jafaripur](https://avatars.githubusercontent.com/u/5066430?v=4)](https://github.com/jafaripur "jafaripur (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/voodoo-mobile-yii2-queue/health.svg)

```
[![Health](https://phpackages.com/badges/voodoo-mobile-yii2-queue/health.svg)](https://phpackages.com/packages/voodoo-mobile-yii2-queue)
```

###  Alternatives

[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[urbanindo/yii2-queue

Queue component for Yii2

11449.9k](/packages/urbanindo-yii2-queue)[keboola/storage-api-client

Keboola Storage API PHP Client

10387.5k25](/packages/keboola-storage-api-client)[sproutcms/cms

Enterprise content management and framework

241.6k4](/packages/sproutcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
