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.
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.
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.