Back to rankings

yiisoft/yii2-queue

PHPyiiframework.com

Yii2 Queue Extension. Supports DB, Redis, RabbitMQ, Beanstalk and Gearman

yii2queueredisamqpgearmanasyncbeanstalkrabbitmqhacktoberfest
Star Growth
Stars
1.1k
Forks
283
Weekly Growth
Issues
64
5001k
Aug 2015Mar 2019Nov 2022Jul 2026
ArtifactsPackagistcomposer require yiisoft/yii2-queue
README

Yii Framework

Yii2 Queue Extension


An extension for running tasks asynchronously via queues.

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

Latest Stable Version Total Downloads build codecov Static Analysis

Installation

[!IMPORTANT]

  • The minimum required PHP version is PHP 8.3.

The preferred way to install this extension is through composer:

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

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.
Yii::$app->queue->isWaiting($id);

// Check whether a worker got the job from the queue and executes it.
Yii::$app->queue->isReserved($id);

// Check whether a worker has executed the job.
Yii::$app->queue->isDone($id);

Documentation

Support the project

Open Collective

Follow updates

Official website Follow on X Telegram Slack

License

License

Related repositories
yiisoft/yii2

Yii 2: The Fast, Secure and Professional PHP Framework

PHPPackagistBSD 3-Clause "New" or "Revised" Licenseyiiphp
yiiframework.com
14.3k6.8k
humhub/humhub

HumHub is an Open Source Enterprise Social Network. Easy to install, intuitive to use and extendable with countless freely available modules.

PHPPackagistOthersocial-networkphp
humhub.com
6.7k1.7k
fecshop/yii2_fecshop

yii2 ( PHP ) fecmall(fecshop) core code used for ecommerce shop 多语言多货币多入口的开源电商 B2C 商城,支持移动端vue, app, html5,微信小程序微店,微信小程序商城等

PHPPackagistBSD 3-Clause "New" or "Revised" Licenseyii2-fecshopyii2
fecmall.com
5.3k1.4k
craftcms/cms

Build bespoke content experiences with Craft.

PHPPackagistOthercmscraftcms
craftcms.com
3.6k705
forecho/awesome-yii2

Yii2 干货集

MIT Licenseyii2
1.8k533
jianyan74/rageframe2

一个基于 Yii2 高级框架的快速开发应用引擎

PHPPackagistApache License 2.0yii2rageframe2
rageframe.com
1.7k582
yiisoft/yii2-app-advanced

Yii 2.0 Advanced Application Template

PHPPackagistBSD 3-Clause "New" or "Revised" Licenseyiiyii2
yiiframework.com
1.7k1.3k
samdark/yii2-cookbook

Yii 2.0 Community Cookbook

Makefileyii2book
1.4k288
yii-starter-kit/yii2-starter-kit

Yii2 Starter Kit

PHPPackagistOtheryii2cms
yii2-starter-kit.terentev.net
1.4k621
dmstr/yii2-adminlte-asset

AdminLTE Asset Bundle for Backend Theme in Yii2 Framework

PHPPackagistyii2-assetyii2
1.1k412
dektrium/yii2-user

[ABANDONED] Flexible user registration and authentication module for Yii2

PHPPackagistyii2-useryii2
yii2-user.dektrium.com
924633
luyadev/luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.

PHPPackagistphpluya
luya.io
811207