Laravel queues in production: 7 mistakes I fix on almost every client app

2026-11-21来源 dev.toEnglish

Queues are where Laravel apps quietly break. Emails stop going out, invoices aren't generated, and nobody notices until a customer complains. These are the seven queue problems I find most often when I take over a client's Laravel app.

1. QUEUE_CONNECTION=sync in production

The app "works", but every job runs inside the web request. A slow PDF or an API call to a payment gateway now blocks the user's page. Use database at minimum, and redis once you have real traffic.

2. No process manager

Someone ran php artisan queue:work in an SSH session months ago. The server rebooted and the worker never came back. Run workers under Supervisor (or Horizon on Redis), with autorestart=true.

3. Workers never restarted after a deploy

Queue workers are long-running processes. They keep running the old code until restarted. Add this to every deploy script:

php artisan queue:restart 

4. No failed_jobs table, or nobody looks at it

Failed jobs are your error log for background work. Make sure the table exists, then check it weekly or alert on it:

php artisan queue:failed php artisan queue:retry all 

5. No timeouts or retries on jobs

One stuck HTTP call can hold a worker forever. Set them explicitly on the job:

public $tries = 3; public $timeout = 60; public $backoff = [10, 60, 300]; 

Make sure the worker's --timeout is shorter than the queue's retry_after, or the same job can run twice.

6. Passing whole models with huge relations

SerializesModels only stores the model ID, but if you eager-load big relations before dispatching, they get re-queried on every attempt. Dispatch with the ID or a lean model, and load what you need inside handle().

7. Everything on one queue

Password-reset emails wait behind a 20-minute CSV export. Split them:

php artisan queue:work --queue=high,default,low 

Put user-facing mail on high and reports and exports on low.

Quick health check: Is the worker running under Supervisor or Horizon? Does the deploy restart it? Is failed_jobs empty? If any answer is "not sure", that's the first thing to fix.

I do this kind of production clean-up as part of my Laravel work. More about how I build and run apps here: Web development services.

Arun Tyagi is a freelance Laravel developer in Noida, India.

原文:https://www.a8q9.cn/en/article/laravel-queues-in-production-7-mistakes-i-fix-on-almost-every-client-app-e9dd6a.html

相关文章