Search

Laravel Artisan Queue Command: The queue:listen Command

December 7, 2016 —John Koster

The queue:listen command is used to listen for and process jobs as they are added to the job queue. The command defines numerous parameters and options that can be used to customize how the queue listener interacts with and behaves under different circumstances. The following table lists and describes each of these options:

Argument/Option Description Default
connection The name of the connection. This argument assumes the value of the QUEUE_DRIVER environment variable. If the QUEUE_DRIVER environment variable has not been set, it will default to sync.
--queue The queue to listen on. Also used to set queue priority. default
--memory The memory limit, in megabytes. 128
--timeout The number of seconds a job can run before timing out. 60
--sleep The number of seconds to wait before checking the queue for jobs. 3
--tries The number of times to attempt a job before logging it as failed. 0

The queue listener connection must be set to one of the values that are defined in the queue.connections configuration array. The following table lists all of the connection names that are available by default (most of the connections need to be configured before they can be used):

Connection Name Driver/Notes
sync Synchronous. All jobs will be processed immediately.
database database
beanstalkd beanstalkd
sqs sqs
redis redis

The --tries option is set to 0 by default, which means that the queue listener will continue to attempt to run a job indefinitely.

The --queue option can be used to specify multiple queues, and the order in which queue jobs should be processed. The following example specifies two queues (high and low). This means that all jobs from the high queue will be processed before any jobs in the low queue will be processed:

1# Set queue priorities.
2php artisan queue:listen --queue=high,low

The following examples demonstrate how to call the queue:listen command with various different options supplied:

1# Set the connection name.
2php artisan queue:listen sync
3 
4# Log a job as failed if processing fails five times.
5php artisan queue:listen --tries=5
6 
7# Set the process timeout to two minutes.
8php artisan queue:listen --timeout=120
9 
10# Set the memory limit to 256 megabytes.
11php artisan queue:listen --memory=256

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.