barryvdh / laravel-async-queue
该包已被 弃用 并不再维护。未建议替代包。
Laravel 的异步队列驱动程序(推送到后台)
v0.7.5
2021-05-17 08:26 UTC
Requires
- php: >=7
- illuminate/console: ^6|^7|^8
- illuminate/support: ^6|^7|^8
- symfony/process: ^4|^5
README
将函数/闭包推送到后台。
对于 Laravel 5.4,请查看 0.6 分支
对于 Laravel 5.3,请查看 0.5 分支
就像 'sync' 驱动程序一样,这不是一个真正的队列驱动程序。它总是立即触发。唯一的区别是将闭包发送到后台而不等待响应。这个包更适合作为在没有设置“真实”队列驱动程序的情况下运行后台任务的替代方案。
注意:这是使用 DatabaseQueue,所以请确保首先设置它,包括迁移。
安装
使用 Composer 需要此包的最新版本
composer require barryvdh/laravel-async-queue
将服务提供者添加到 config/app.php 中的 providers 数组
Barryvdh\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