Laravel Queues

Print Print
Reading time 1:6

Laravel's queue system lets slow or resource-intensive tasks, such as sending an email or processing an uploaded file, be deferred and run in the background instead of blocking the current web request. This improves response times for end users while the work is handled asynchronously by a separate worker process.

Queue Drivers

Laravel provides a unified API across several queue backends, including database, Redis, and Amazon SQS, configured through the queue.php configuration file. Switching between drivers generally requires no changes to application code.

Creating a Job

Generate a job class

php artisan make:job ProcessPodcast

Job classes implement a handle method containing the work to be performed, and are dispatched using the job's dispatch method.

Dispatching a job

ProcessPodcast::dispatch($podcast);

Running a Worker

Start a queue worker

php artisan queue:work

The worker process continuously pulls jobs off the queue and executes them. In production, a process monitor such as Supervisor is typically used to keep the worker running and restart it if it stops.

Failed Jobs

If a job throws an exception, Laravel can retry it automatically up to a configured number of attempts. Jobs that continue to fail are recorded in a failed_jobs table, and can be inspected or retried later using Artisan commands.

By: Tomas Silny
Edited: 2026-08-13 03:31:20