What is the difference queue:work and queue:listen

匿名 (未验证) 提交于 2019-12-03 08:35:02

问题:

I can't understand what's the difference between Laravel queue:work and Laravel queue:listen

I can see that:

  • Queue: Listen to a given queue
  • Work: Process the next job on a queue

But still don't get it, because I've tried both, both will run queue if there is any new queue ("work option" not just running once)

I'm not talking about the daemon option. Just these both.

回答1:

Until Laravel 5.2 you had :listen and :work.

Work would process the first job in the queue.

Listen would process all jobs as they came through.

In Laravel 5.3+ this is no longer the case. Listen still exists, but it is deprecated and slated for removal in 5.5. You should prefer :work now.

Work now process jobs one after the other, but have a plethora of options you can configure.



回答2:

There are two different issues listed.

There is artisan queue:work and artisan queue:listen

queue:work will simply pop off the next job in the queue, and process only that one job. This is a 'one off' command that will return to the command prompt once the one queue command is processed. queue:listen will listen to the queue, and continue to process any queue commands it receives. This will continue running indefinitely until you stop it. In Laravel >=4.2 there was a --daemon command added. The way it works is simply keeps running the queues directly, rather than rebooting the entire framework after every queue is processed. This is an optional command that significantly reduces the memory and cpu requirements of your queue.

The important point with the --daemon command is that when you upgrade your application, you need to specifically restart your queue with queue:restart, otherwise you could potentially get all sorts of strange errors as your queue would still have the old code in memory.

So to answer your question "Which command should I use for running my daemons?" - the answer is almost always queue:work --daemon



回答3:

The queue:work Artisan command includes a --daemon option for forcing the queue worker to continue processing jobs without ever re-booting the framework. This results in a significant reduction of CPU usage when compared to the queue:listen command:

As you can see, the queue:work job supports most of the same options available to queue:listen. You may use the php artisan help queue:work job to view all of the available options.

https://laravel.com/docs/5.1/queues#running-the-queue-listener



回答4:

that's detailed response to how it works in version 5.1



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!