Skip to content
HollyIT
Open menu

Laravel Queue Workers That Don’t Fall Over

Queues are where Laravel apps quietly break in production. Here is the setup I use so workers restart cleanly, retry sensibly and tell you when something is wrong.

Abstract teal bands, like jobs moving through a queue

Most Laravel apps start with QUEUE_CONNECTION=sync and only meet real queues when something gets slow. That is when the surprises arrive: workers that keep running old code after a deploy, jobs that retry forever, and failures nobody hears about.

Keep workers alive, and recycle them

A worker is a long-running PHP process, so it never sees new code until it restarts. Run it under a process monitor, and let it exit on its own every so often so memory leaks can't build up.

[program:app-worker]
command=php /var/www/app/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
numprocs=2
stopwaitsecs=3600

Then make restarting part of every deploy:

php artisan migrate --force
php artisan queue:restart

Retry with intent

Retries should be a decision per job, not a global default. A payment webhook and a thumbnail generator fail for very different reasons.

class SyncInvoiceToAccounting implements ShouldQueue
{
    public int $tries = 5;

    /**
     * Wait longer after each failure: 10s, 1m, 5m, 15m.
     *
     * @return list
     */
    public function backoff(): array
    {
        return [10, 60, 300, 900];
    }

    public function failed(Throwable $exception): void
    {
        Log::channel('slack')->error('Invoice sync gave up', ['invoice' => $this->invoice->id]);
    }
}

Know when it breaks

Failed jobs should land somewhere a human looks. A dashboard of queue depth and failure rate catches the slow problems before customers do.

Abstract violet gradient standing in for a monitoring dashboard
A placeholder for your queue dashboard, placed from the media library.

New to queues altogether? This walkthrough covers the basics well.

A YouTube embed, by Laravel Daily.

The short version

  • Run workers under Supervisor or systemd.
  • Restart them on every deploy, and recycle them with --max-time.
  • Set $tries and backoff() per job.
  • Send failures somewhere people will see them.

The checklist I go through on every project is below, from the media library.

Got something to build, fix or keep standing?

Got something to build, fix or keep standing?

Tell me what you are working on. You will get a reply from me, usually within a working day.

Prefer to email or call?