genesisweb / laravel-async-queue
Laravel 异步队列驱动(后台推送)(基于 Barryvdh 分支)
v0.7.3
2019-09-07 10:02 UTC
Requires
- php: >=7
- illuminate/console: 5.5.x|5.6.x|5.7.x|5.8.x|6.0.x
- illuminate/support: 5.5.x|5.6.x|5.7.x|5.8.x|6.0.x
- symfony/process: ^3.2|^4
README
将函数/闭包推送到后台。
##### 为 Laravel 6 支持而分支,所有功劳归功于 Barryvdh。
对于 Laravel 5.4,请查看 0.6 分支
对于 Laravel 5.3,请查看 0.5 分支
就像 'sync' 驱动一样,这并不是一个真正的队列驱动。它总是立即触发。唯一的区别是,闭包被发送到后台,而不需要等待响应。这个包作为在后台运行临时任务的一个替代方案,更易于使用,无需设置“真正的”队列驱动。
注意: 这个包使用 DatabaseQueue,所以请确保首先设置好,包括迁移。
安装
使用 Composer 需求此包的最新版本
composer require genesisweb/laravel-async-queue
将 Service Provider 添加到 config/app.php 中的 providers 数组
GenesisWeb\Queue\AsyncServiceProvider::class,
您需要创建队列迁移表并运行它。
$ php artisan queue:table
$ php artisan migrate
现在您应该可以使用 config/queue.php 中的异步驱动。使用与数据库相同的配置,但使用异步作为驱动。
'connections' => array(
...
'async' => array(
'driver' => 'async',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
),
...
}
将默认值设置为 async
,通过更改配置或将 QUEUE_DRIVER
在 .env
文件中设置为 async
。
注意:默认情况下,使用
php
作为 PHP 的二进制路径。您可以通过向队列配置中添加binary
选项来更改此设置。您还可以添加额外的参数(例如 HHVM)
'connections' => array(
...
'async' => array(
'driver' => 'async',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
'binary' => 'php',
'binary_args' => '',
),
...
}
它应该与同步驱动具有相同的效果,因此不需要运行队列监听器。缺点是您实际上无法排队或计划事情。Queue::later() 也直接触发。更多信息请参阅 https://laravel.net.cn/docs/queues