运行队列
# 运行队列处理程序
php artisan queue:work
# 运行队列处理程序
php artisan queue:listen
# 指定任务处理器使用哪一个链接,链接名在 config/queue.php 中定义
php artisan queue:work redis
# 指定任务处理器使用的链接和处理的队列名称
php artisan queue:work redis --queue=emails
# 只处理队列中的下一个任务
php artisan queue:work --once
# 指定任务处理器处理了多少个任务后关闭
php artisan queue:work --max-jobs=1000
# 指定任务处理器处理全部任务后关闭
php artisan queue:work --stop-when-empty
# 指定任务处理器处理了多少秒后关闭
php artisan queue:work --max-time=3600
# 指定队列处理的优先级
php artisan queue:work --queue=high,low
# 优雅地从新启动全部的 worker,需配合Supervisor来自动重启
php artisan queue:restart
# 指定队列执行的超时时间
php artisan queue:work --timeout=60
# 设置队列为空时的休眠时间
php artisan queue:work --sleep=3
queue:work
与 queue:listen
区别
queue:listen
一旦命令启动,将一直保持运行,直到它被手动中止或关闭终端。当新的请求到来时,会从新加载整个框架,因此更新代码后无需手动从新启动队列处理器便可生效。但性能不如 queue:work
好。
queue:work
一旦命令启动,将一直保持运行,直到它被手动中止或关闭终端。当新的请求到来时,不从新加载整个框架,而是直接执行程序。更新代码后,须要从新启动队列处理器,代码才生效。
queue:work
全部参数说明
protected $signature = 'queue:work
{connection? : The name of the queue connection to work}
{--queue= : The names of the queues to work}
{--daemon : Run the worker in daemon mode (不推荐使用)}
{--once : Only process the next job on the queue}
{--stop-when-empty : Stop when the queue is empty}
{--delay=0 : The number of seconds to delay failed jobs}
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--timeout=60 : The number of seconds a child process can run}
{--tries=1 : Number of times to attempt a job before logging it failed}';