Skip to content

wangjun083/yii2-queue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Queue component for Yii2

This component providers simple queue warpper

Requirements

redis

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist wayhood/yii2-queue "*"

or add

"wayhood/yii2-queue": "*"

to the require section of your composer.json file.

Usage

To use this extension, simply add the following code in your application configuration:

return [
    //....
    'components' => [
        'queue' => [
            'class' => 'wh\queue\RedisQueue',
            'redis' => [
                'hostname' => 'localhost',
                'port' => 6379,
                'database' => 0
            ]
        ],
    ],
];

The first create a Job process Class

namespace console\jobs;

class MyJob
{
    public function run($job, $data)
    {
        //process $data;
        var_dump($data);
    }
} 

than set data to queue

#Default is run "run" method
Yii::$app->queue->push('\console\jobs\MyJob', ['a', 'b', 'c']);

#or other method name
Yii::$app->queue->push('\console\jobs\MyJob@run', ['a', 'b', 'c']);

Command woker and listen

return [
    // ...
    'controllerMap' => [
        'queue' => 'wh\queue\console\controllers\QueueController'
    ],
];

Below are some command usages of this command:

#process a job and run, than exit process
yii queue/work 

#a loop process job
yii queue/listen

About

Queue warper for yii2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%