zhuravljov / yii2-queue
2.3.7
2024-04-29 09:40 UTC
Requires
- php: >=5.5.0
- symfony/process: ^3.3||^4.0||^5.0||^6.0||^7.0
- yiisoft/yii2: ~2.0.14
Requires (Dev)
- aws/aws-sdk-php: >=2.4
- cweagans/composer-patches: ^1.7
- enqueue/amqp-lib: ^0.8||^0.9.10||^0.10.0
- enqueue/stomp: ^0.8.39||^0.10.0
- opis/closure: *
- pda/pheanstalk: ~3.2.1
- php-amqplib/php-amqplib: ^2.8.0||^3.0.0
- phpunit/phpunit: 4.8.34
- yiisoft/yii2-debug: ~2.1.0
- yiisoft/yii2-gii: ~2.2.0
- yiisoft/yii2-redis: ~2.0.0
Suggests
- ext-gearman: Need for Gearman queue.
- ext-pcntl: Need for process signals.
- aws/aws-sdk-php: Need for aws SQS.
- enqueue/amqp-lib: Need for AMQP interop queue.
- enqueue/stomp: Need for Stomp queue.
- pda/pheanstalk: Need for Beanstalk queue.
- php-amqplib/php-amqplib: Need for AMQP queue.
- yiisoft/yii2-redis: Need for Redis queue.
- 3.0.x-dev
- dev-master / 2.x-dev
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.1.0
- 1.0.1
- 1.0.0
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.0
- 0.10.1
- 0.10.0
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- dev-update-changelog
- dev-update-composer-json
- dev-fix-build
- dev-enh87
This package is auto-updated.
Last update: 2024-04-29 09:50:14 UTC
README
Yii2 队列扩展
一个用于通过队列异步执行任务的扩展。
它支持基于 DB、Redis、RabbitMQ、AMQP、Beanstalk、ActiveMQ 和 Gearman 的队列。
文档位于 docs/guide/README.md。
安装
安装此扩展的首选方式是通过 composer
php composer.phar require --prefer-dist yiisoft/yii2-queue
基本用法
发送到队列的每个任务都应该定义为一个单独的类。例如,如果您需要下载并保存文件,类可能如下所示
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)); } }
以下是向队列发送任务的方法
Yii::$app->queue->push(new DownloadJob([ 'url' => 'http://example.com/image.jpg', 'file' => '/tmp/image.jpg', ]));
将作业推送到队列,使其在5分钟后运行
Yii::$app->queue->delay(5 * 60)->push(new DownloadJob([ 'url' => 'http://example.com/image.jpg', 'file' => '/tmp/image.jpg', ]));
任务执行的准确方式取决于使用的驱动程序。大多数驱动程序都可以通过控制台命令运行,组件会自动在您的应用程序中注册这些命令。
此命令循环获取并执行任务,直到队列为空
yii queue/run
此命令启动一个守护进程,无限期地查询队列
yii queue/listen
有关特定驱动程序的控制台命令及其选项的更多详细信息,请参阅文档。
组件还具有跟踪已推送到队列的作业状态的能力。
// 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);
有关更多详细信息,请参阅 指南。