Laravel Horizon Documentation
repository·5.x·Indexed 26 days ago
https://github.com/laravel/horizonA dashboard and configuration system for managing Redis-powered queues in Laravel applications. Horizon provides real-time monitoring of job metrics, code-driven worker configuration, and tools for managing supervisor environments, auto-scaling, and job tagging. It includes features for routing LongWaitDetected notifications via Email, Slack, and SMS, as well as utilities for managing job payloads and snapshot retention.
What's inside Laravel Horizon
- Laravel Horizon provides a dashboard and code-driven configuration for Laravel-powered Redis queues. It allows you to monitor key metrics such as job throughput, runtime, and job failures. Worker configurations are managed in a single configuration file, enabling version control and team collaboration.
Route Horizon notifications in HorizonServiceProvider
5.xYou can configure where Horizon sends
LongWaitDetectedalerts by using the built-in routing methods within theboot()method of yourApp\Providers\HorizonServiceProvider. Horizon automatically wires theLongWaitDetectedevent to these routes.Available routing methods:
Horizon::routeMailNotificationsTo(...)Horizon::routeSlackNotificationsTo(...)Horizon::routeSmsNotificationsTo(...)
Configure Horizon supervisor environments
5.xHorizon uses a hierarchical configuration structure for supervisors. The
defaultsarray defines the base configuration for all supervisors. Theenvironmentsarray is used to patch these defaults for specific environments (e.g.,production).Important: The
environmentsarray merges intodefaultsrather than replacing it. You only need to specify the keys you wish to override in your environment-specific blocks.Use automatic Eloquent model tagging in Horizon
5.xHorizon automatically tags jobs that accept Eloquent model instances in their constructor. The tag format isModelClass:id(e.g.,App\Models\User:42). These tags are immediately available for filtering in the Horizon dashboard. You only need to implement atags()method in your job class if you require custom tags in addition to this automatic behavior.Upgrade to Horizon 5.0 from 4.x
5.xWhen upgrading to version 5.0, ensure your environment meets the following requirements and note the following breaking changes:
Requirements
- Minimum PHP Version: PHP 7.3
- Minimum Laravel Version: Laravel 8.0
Breaking Changes
- Chronos Replaced By Carbon: Internal usage of Chronos has been replaced by Carbon for ecosystem consistency.
- Deprecated Flags: The following flags are deprecated and should be replaced:
- Replace
timeoutAtwithretryUntil. - Replace
delaywithbackoff.
- Replace
Maintain a fixed number of workers with `balance: false`
5.xIf you need a queue to always have a constant number of workers (for example, to limit resource usage for a heavy video-processing task), do not use auto-balancing. Instead, setbalance: falseand define a specificmaxProcessesvalue.Upgrade to Horizon 3.0 from 2.x
5.xWhen upgrading to version 3.0, ensure your environment meets the following requirement:
Requirements
- Minimum Laravel Version: Laravel 5.7 is the minimum required version. You must upgrade to this version to continue using Horizon.
Populate the Metrics dashboard using horizon:snapshot
5.xThe Horizon metrics dashboard will remain blank unless snapshots are generated. Running thehorizonartisan command does not automatically populate metrics. To build the metrics graph, you must schedule thehorizon:snapshotcommand to run periodically (recommended every 5 minutes) using Laravel's scheduler.Enforce queue priority using separate supervisors
5.xWhen using
balance: autoon a single supervisor, Horizon ignores the order of thequeuearray for load balancing purposes. To ensure specific queues are processed with higher priority, you must create separate named supervisors.For example, to prioritize a
notificationsqueue over adefaultqueue, create one supervisor fornotificationswith a highermaxProcessesand a second supervisor fordefaultwith a lowermaxProcessescap.Upgrade to Horizon 4.0 from 3.x
5.xWhen upgrading to version 4.0, ensure your environment meets the following requirements and note the following breaking changes:
Requirements
- Minimum Laravel Version: Laravel 7.0
Breaking Changes
- Predis Dependency: Predis is no longer a required dependency. If you wish to continue using Predis, you must explicitly add it to your
composer.jsonfile. - Default Predis Prefix: The default Predis prefix now starts with the application name. To maintain the old prefix behavior, add the following to your
.envfile:
HORIZON_PREFIX="horizon:"- Command Rename: The
horizon:assetscommand has been renamed tohorizon:publish.
Silence jobs by tags in the Horizon dashboard
5.xYou can hide all jobs that carry a specific tag from the completed jobs view by using thesilenced_tagsconfiguration option inconfig/horizon.php. This is useful for silencing entire categories of jobs (e.g., allnotifications) without needing to list every individual job class.Configure LongWaitDetected threshold in config/horizon.php
5.xTo control when Horizon fires a
LongWaitDetectedevent, adjust thewaitsarray in yourconfig/horizon.phpfile. The value defines the maximum number of seconds a job can wait in a specific queue before the event is triggered. For example,'redis:default' => 60means jobs in thedefaultqueue will trigger an alert if they wait longer than 60 seconds.Note: Adjust this configuration value to change alert frequency; do not attempt to change this via notification routing.