brandoriented / laravel-async-queue
Laravel的异步队列驱动程序(推送到后台)
v0.7.0
2017-09-01 09:25 UTC
Requires
- php: >=5.6.4
- illuminate/console: 5.4.x|5.5.x
- illuminate/support: 5.4.x|5.5.x
- symfony/process: ~3.2
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
,通过更改配置或在.env文件中将QUEUE_DRIVER
设置为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