Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between queue:work --daemon and queue:listen

I'm settin up my offline job server. I've read the documentation but I still don't really see the differences between the two commands: artisan queue:work --daemon and artisan queue:listen. Which command should I use for running my daemons?

like image 251
Logan Bailey Avatar asked Sep 25 '14 21:09

Logan Bailey


People also ask

What is the difference between queue work and 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.

What is daemon in Laravel?

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.

How does queue work in Laravel?

Laravel queues provide a unified API across a variety of different queue backends, such as Beanstalk, Amazon SQS, Redis, or even a relational database. Queues allow you to defer the processing of a time consuming task, such as sending an email, until a later time.

What are queues and jobs?

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.


1 Answers

Edit updated 2017-04-07:

There are now three ways to run your queue:

  • queue:work - this is the new "daemon" process (the flag is no longer required). The framework will fire up "once" - and then keep looping through the jobs. This will continue indefinitely. It uses less memory/cpu than queue:listen because the framework stays up the entire time. You must also remember to use queue:restart to force the queue to update any code changes you push during patching.

  • queue:work --once - this will fire up the framework, process one job, then shutdown. Useful for testing during development etc.

  • queue:listen - this will fire the framework up on every cycle, process one job, then fully shutdown, and then fire the framework up again etc and loop indefinitely. This means all memory/processes are released after each job is processed. If you have memory leaks with queue:work - give this a try.

The --daemon flag no longer has an effect on these commands.

Original answer:

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

like image 195
Laurence Avatar answered Sep 22 '22 15:09

Laurence