Skip to main content

Cloudsoft Zone Build, deploy and scale with practical guides to PHP, Node.js, React, DevOps and AI automation. Explore the guides

Cloudsoft Zone
LaravelTutorial

Laravel Horizon setup guide: monitored Redis queues in Laravel 13

Install Laravel Horizon 5 on Laravel 13, configure supervisors and balancing, set retries and timeouts safely, secure the dashboard and run it under Supervisor.

Nilesh Kushvaha

Updated 8 min read

Cloudsoft Zone cover: Laravel Horizon setup guide: monitored Redis queues in Laravel 13
Image: Cloudsoft Zone
In this article

Laravel Horizon is the official dashboard and process manager for Redis queues. You install it with Composer, describe your workers in config/horizon.php, run a single php artisan horizon command, and get live throughput, wait times and failed jobs in a browser. This guide sets it up on Laravel 13 with Horizon 5, step by step, including the settings that most often cause duplicate or killed jobs in production.

A Laravel Horizon setup on Laravel 13 with Horizon 5 comes down to three things: supervisors configured per environment, retries and timeouts that avoid duplicate or killed jobs, and dashboard access restricted through the viewHorizon gate.

Everything below was checked against the Laravel 13.x Horizon and queue documentation and the Horizon 5.x source on 10 October 2026. At that date the latest releases were Laravel 13.35.0 and Horizon 5.50.0.

What Horizon adds to Laravel queues

Plain Laravel queues already work: you dispatch a job, and php artisan queue:work processes it. The trouble starts when you have several queues, several servers and no visibility. Horizon solves three problems:

  • Configuration in code. Worker counts, queues, retries and timeouts live in one version-controlled file, per environment.
  • Automatic balancing. Horizon can move worker processes to whichever queue is busiest.
  • Visibility. A dashboard at /horizon shows pending, completed and failed jobs, runtimes, throughput and tags, and Horizon can alert you when a queue waits too long.

There are limits to know before you start. Horizon works only with the Redis queue driver, it does not support Redis Cluster, and the package requires the pcntl and posix PHP extensions, so it runs on Linux and macOS but not natively on Windows (use WSL2, Docker or Sail there).

Step 1: install Horizon

Make sure your queue connection is Redis. In .env:

Shell
QUEUE_CONNECTION=redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

Then install the package and publish its files:

Shell
composer require laravel/horizon
php artisan horizon:install

horizon:install creates config/horizon.php and app/Providers/HorizonServiceProvider.php. One detail from the documentation is easy to miss: Horizon uses a Redis connection named horizon internally, so do not define your own Redis connection with that name.

Step 2: configure supervisors per environment

The environments key maps each APP_ENV value to one or more supervisors. A supervisor is a group of worker processes with its own queues and balancing rules. Values in the defaults key are merged into every supervisor, so you only override what differs.

Here is a practical production setup with a fast lane for user-facing work and a capped lane for heavy jobs:

PHP
// config/horizon.php
'defaults' => [
    'supervisor-1' => [
        'connection' => 'redis',
        'queue' => ['default'],
        'balance' => 'auto',
        'autoScalingStrategy' => 'time',
        'maxProcesses' => 1,
        'memory' => 128,
        'tries' => 3,
        'timeout' => 60,
    ],
],

'environments' => [
    'production' => [
        'supervisor-1' => [
            'queue' => ['default', 'notifications'],
            'minProcesses' => 1,
            'maxProcesses' => 10,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
            'maxJobs' => 1000,
            'maxTime' => 3600,
        ],
        'supervisor-media' => [
            'connection' => 'redis-long',
            'queue' => ['media'],
            'balance' => 'simple',
            'processes' => 2,
            'tries' => 2,
            'timeout' => 300,
        ],
    ],

    'local' => [
        'supervisor-1' => [
            'maxProcesses' => 3,
        ],
    ],
],

Add an entry for every environment where you run Horizon. If APP_ENV=staging and there is no staging key (and no * wildcard), no workers start.

Choosing a balancing strategy

StrategyHow workers are assignedUse it when
auto (default)Scales processes per queue between minProcesses and maxProcesses based on workloadLoad varies and queues are roughly equal in importance
simpleSplits a fixed processes count evenly across the queuesYou want predictable resource use, for example heavy media jobs
falseProcesses queues strictly in listed order, still scaling total processesOne queue must always drain before the next

With auto, the autoScalingStrategy option decides how workers are shared: time uses the estimated time to clear each queue, size uses the number of jobs, and log uses the logarithm of the job count so one huge queue cannot take every worker. Note that under auto the order of queues in the list does not create a priority. If you need a guaranteed lane, use a separate supervisor, as with supervisor-media above.

Step 3: get retries and timeouts right

Most production queue incidents come from three numbers that disagree with each other. Keep this order:

  1. Job timeout (the #[Timeout] attribute or the job's timeout) is the shortest.
  2. Horizon supervisor timeout is longer than any job timeout on that supervisor.
  3. retry_after on the redis connection in config/queue.php (90 seconds by default) is a few seconds longer than the Horizon timeout.

If retry_after is shorter than the time a job really runs, Redis hands the same job to a second worker and it runs twice. If the Horizon timeout is shorter than a job's own timeout, the documentation warns that Horizon can treat the worker as hanging and kill it mid-job while scaling down.

The supervisor-media lane above allows jobs up to 300 seconds, which is longer than the default 90-second retry_after. Give long jobs their own Redis queue connection in config/queue.php instead of raising retry_after for everything:

PHP
// config/queue.php, inside 'connections'
'redis-long' => [
    'driver' => 'redis',
    'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
    'queue' => 'media',
    'retry_after' => 330,
    'block_for' => null,
    'after_commit' => false,
],

Laravel 13 lets you set the job's own limits with attributes on the job class:

PHP
<?php

namespace App\Jobs;

use App\Models\Video;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\Timeout;
use Illuminate\Queue\Attributes\Tries;
use Throwable;

#[Tries(3)]
#[Timeout(240)]
#[Backoff([10, 60, 300])]
class TranscodeVideo implements ShouldQueue
{
    use Queueable;

    public function __construct(public Video $video)
    {
        $this->onConnection('redis-long');
        $this->onQueue('media');
    }

    public function handle(): void
    {
        // Transcode the file...
    }

    public function failed(?Throwable $exception): void
    {
        $this->video->update(['status' => 'failed']);
    }

    /**
     * @return array<int, string>
     */
    public function tags(): array
    {
        return ['media', 'video:'.$this->video->id];
    }
}

A value set on the job takes precedence over the supervisor's tries. If you leave tries unset everywhere, Horizon makes a single attempt. Middleware such as WithoutOverlapping or RateLimited releases jobs back to the queue and uses attempts, so raise tries for jobs that use them.

Step 4: secure the dashboard

The dashboard lives at /horizon. In the local environment anyone can open it; everywhere else access is controlled by the viewHorizon gate in HorizonServiceProvider. Replace the placeholder with a real rule:

PHP
use App\Models\User;
use Illuminate\Support\Facades\Gate;

protected function gate(): void
{
    Gate::define('viewHorizon', function (User $user) {
        return $user->is_admin === true;
    });
}

The is_admin column is an example; use whatever role or permission check your application already has. The dashboard can retry and delete jobs and shows job payloads, so treat it as an admin tool. If you serve a Content Security Policy, Horizon supports a nonce through Horizon::cspNonce() called from middleware listed in the middleware option of config/horizon.php.

Step 5: metrics, tags and alerts

The metrics graphs stay empty until you schedule snapshots. In routes/console.php:

PHP
use Illuminate\Support\Facades\Schedule;

Schedule::command('horizon:snapshot')->everyFiveMinutes();

Horizon tags jobs automatically with any Eloquent models in their properties, such as App\Models\Video:42, which lets you search the dashboard for every job that touched one record. The tags() method in the job above adds your own tags.

For alerts, set thresholds in the waits option (seconds per connection:queue, 60 by default) and route notifications in the provider's boot method:

PHP
public function boot(): void
{
    parent::boot();

    Horizon::routeMailNotificationsTo('ops@example.com');
    Horizon::routeSlackNotificationsTo(config('services.slack.horizon_webhook'), '#queues');
}

Noisy jobs you never need to inspect can be hidden with the silenced or silenced_tags options, or by implementing Laravel\Horizon\Contracts\Silenced.

Step 6: run Horizon in production

Horizon is a long-running process, so a process monitor must restart it if it exits. On Ubuntu, install Supervisor and add /etc/supervisor/conf.d/horizon.conf:

INI
[program:horizon]
process_name=%(program_name)s
command=php /var/www/example.com/artisan horizon
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
stdout_logfile=/var/www/example.com/storage/logs/horizon.log
stopwaitsecs=3600
Shell
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start horizon

Set stopwaitsecs longer than your longest job, or Supervisor may kill a job that is still finishing. Then add one line to every deployment, after the new code is in place:

Shell
php artisan horizon:terminate

This lets running jobs finish, stops Horizon, and Supervisor starts it again on the new code. Without it, workers keep running the old code in memory. Useful commands for day-to-day work are horizon:status, horizon:pause and horizon:continue, and horizon:pause-supervisor supervisor-media to stop one lane during maintenance. Locally, php artisan horizon:listen restarts Horizon when files change (it needs Node and the chokidar package).

Laravel Horizon setup gotchas and what to do next

  • Jobs run twice: check that retry_after is longer than the Horizon timeout, and that both are longer than real job runtimes.
  • Nothing processes in staging: the environment name has no entry under environments.
  • Maintenance mode: Horizon does not process jobs during php artisan down unless a supervisor sets 'force' => true.
  • Memory creep: keep memory at a sensible limit and set maxJobs or maxTime so workers restart periodically.
  • Mixed drivers: Horizon manages Redis queues only. If a failover queue uses the database driver, run a normal queue:work database process beside it.
  • Redis memory: the trim option controls how many minutes Horizon keeps recent, completed and failed job records; shorten it if Redis is small.

Next, load-test one busy queue with realistic jobs and watch the wait-time graph. If waits grow, raise maxProcesses or move slow work to its own supervisor before you add servers.

Frequently asked questions

  • Does Laravel Horizon work without Redis?

    No. Horizon only manages queues on the redis driver and does not support Redis Cluster. For the database or SQS drivers, use php artisan queue:work with your own process monitor.

  • Can I run Horizon on Windows?

    Not natively. The package requires the pcntl and posix PHP extensions, which are not available on Windows. Run it inside WSL2, Docker or Laravel Sail.

  • Why do my Horizon jobs sometimes run twice?

    Usually because retry_after on the Redis queue connection is shorter than the time the job really takes, so another worker picks it up. Keep job timeout < Horizon timeout < retry_after.

  • How do I restart Horizon after a deployment?

    Run php artisan horizon:terminate. Horizon finishes current jobs and exits, and your process monitor (such as Supervisor) starts it again with the new code.

  • Who can see the Horizon dashboard in production?

    Only users allowed by the viewHorizon gate in App\Providers\HorizonServiceProvider. In the local environment the dashboard is open to everyone.

  • Why are the Horizon metrics graphs empty?

    Metrics come from snapshots. Schedule horizon:snapshot to run every five minutes in routes/console.php and make sure the Laravel scheduler is running.

Sources

  1. Laravel Horizon (Laravel 13.x) — Laravel
  2. Queues (Laravel 13.x) — Laravel
  3. Horizon default configuration file, 5.x branch — Laravel (GitHub)
  4. laravel/horizon composer.json, 5.x branch — Laravel (GitHub)
  5. laravel/horizon releases — Laravel (GitHub)
  6. Supervisor: A Process Control System — Supervisor

New tools, once a week

One short email listing what joined the directory.

The weekly email about new tools and occasional newsletters. Unsubscribe at any time.

Comments

No comments yet. Be the first to join the conversation.

Leave a comment

Every comment is read by a moderator before it appears. Your email address is never published; it is used only to contact you about this comment.

Never published. Used only to contact you about this comment.

Loading the security check…

Comments are moderated before publication.