Someone on StackOverflow recently asked for a very basic explanation of what the differences are between Events, Listeners, Queues, and Jobs in Laravel. Specifically, the poster requested that the answer be explained as if he or she was only 5. As Events, Listeners, Queues, and Jobs can be confusing, I thought it might be worth posting my response, in the hopes that it might be useful to anyone who might be wondering the same thing.




Although they all can work together, I find it’s easiest to look at Events and Listeners together, and then Jobs and Queues together.

Events and Listeners

Events are objects that hold data that are “fired”, the Laravel event system “catches” the event object when it is fired, and then all the Listeners that are registered for that particular event are run.

If you think about it, this is akin to how exceptions work. You throw an exception, and you can define several catch blocks to react depending on which exception is thrown. In the case of Events and Listeners, an Event is thrown and one or more Listeners represent the contents of a catch block. Though similar, Events and Listeners are not error handlers, they just have conceptual similarities.

Jobs and Queues

I think the best way to think of these is like a line at a bank. The 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. When a daemon is available it will ask the Queue for the next Job like the bank teller asking for the next person in line to step to the window.

Each person in line has a specific task they want accomplished, like making a deposit or withdrawal. The action that the person in line needs completed is the Worker in Laravel.

The Worker is the thing the daemon will do for the Job that was taken from the Queue, just like the task is the thing the bank teller will do for the customer who stepped forward from the line.

Hope any of that makes some sense.