I can't understand what's the difference between Laravel queue:work
and Laravel queue:listen
I can see that:
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.
Jobs and QueuesThe line itself is the Queue, and each customer in the line is a Job. In order to process Jobs in the Queue you need command line processes or daemons. Think of launching a queue daemon on the command line as adding a new bank teller to the pool of available bank tellers.
The Laravel queue service provides a unified API across a variety of different queue back-ends. Queues allow you to defer the processing of a time consuming task, such as sending an e-mail, until a later time which drastically speeds up web requests to your application.
A job queue contains an ordered list of jobs waiting to be processed by a subsystem. The job queue is the first place that a submitted batch job goes before becoming active in a subsystem. The job is held here until a number of factors are met.
You may already know that a daemon is simply a process that runs in the background instead of one that's under the direct control of a user. In Laravel, the command you're probably most familiar with running as a daemon is php artisan horizon , which starts the Horizon master process that spawns all the child workers.
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.
Edit
The above was true at the time of the posting, but since then things have been changed a bit.
queue:work
should be preferred when you want your queue's to run as a daemon
. This would be a long-lived process that would be beneficial where performance was an issue. This will use a cached version of the application and does not re-bootstrap the application every time a job is processed.
queue:listen
should be used when you don't care about performance or you don't want to have to restart the queue after making changes to the code.
In Laravel 5.3+ queue:work runs a daemon listener. It could in 5.2 as well if you specified the --daemon
flag. A daemon work boots the framework one time and then processes jobs repeatedly. The queue:listen
command runs a queue:work --once
sub-process in a loop which boots the framework each iteration.
queue:work
should pretty much always be used in production as it's much more efficient and uses less RAM. However; you need to restart it after each core change. queue:listen
is useful for development and local environments because you don't have to restart it after code changes (because the framework is booting fresh each job).
from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With