5.3
) 有三种方式进行队列消费queue:work
- 这是一个新的后台进程(再也不须要 daemon
标记), 这种方式运行,框架只会启动一次,并保持循环去消费队列,除非出现异常不然该进程将无限时间运行下去。这种方式消耗的 cpu
和 内存
都比 queue:listen
要少,由于在整个生命周期中框架一直是在保持运行状态。同时,使用该方法时若是更新了代码,记得使用 queue:restart
来重启。php
queue:work --once
- 该方法会启动框架,运行 job,而后销毁掉。在开发和测试代码的时候使用比较合适,由于每次都会加载一遍代码嘛。框架
queue:listen
- 这种方式运行,框架每次都会启动,运行job,而后关闭,而后再次启动框架,运行job,而后关闭,这样一直循环(每次运行完一次都会彻底释放掉运行时的内存和进程)。因此这种方式你不用担忧代码的热更新,不用去重启 queue
,随之而来的另一个好处是不用去担忧 queue:work
带来的内存泄漏。测试
注意 从
5.3
版本开始--daemon
这个参数已经再也不起做用了,能够看Illuminate\Queue\Console\WorkCommand.php
rest
protected $signature = 'queue:work {connection? : The name of connection} {--queue= : The queue to listen on} {--daemon : Run the worker in daemon mode (Deprecated)} {--once : Only process the next job on the queue} {--delay=0 : Amount of time 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=0 : Number of times to attempt a job before logging it failed}';