Laravel Horizon is a powerful package that provides an elegant dashboard and configuration system for managing your Laravel queues. If you’re working with Laravel queues, Horizon makes it easy to monitor, configure, and manage jobs running in the background. With Horizon, you can see detailed statistics, job failure rates, and more, making it an essential tool for developers handling complex Laravel applications.

In this blog post, we will walk you through 7 easy steps on how to use Laravel Horizon to monitor queues effectively. Whether you’re a beginner or an experienced Laravel developer, this guide will help you get started and make the most of Horizon.
What Is Laravel Horizon?
Before we dive into the steps, let’s quickly understand what Laravel Horizon is and why it’s useful. Horizon is a queue monitoring package developed by Laravel. It provides a real-time dashboard to monitor your queues, giving you insights into job performance, job failure rates, throughput, and more.
Laravel’s queue system allows you to run jobs (like sending emails, processing uploads, etc.) in the background. However, keeping track of these jobs and ensuring they run smoothly can be a challenge, especially when you have many tasks. That’s where Horizon steps in. It makes managing and monitoring your queues a breeze.
Why Should You Use Laravel Horizon?
Here are some of the key benefits of using Laravel Horizon for monitoring queues:
- Real-Time Monitoring: Horizon provides a real-time dashboard to view the status of your queues and jobs.
- Detailed Metrics: You can track the execution time of jobs, job throughput, and failure rates.
- Easy Configuration: Horizon makes it easy to configure and manage multiple queue connections.
- Retry Failed Jobs: It offers a feature to retry failed jobs manually or automatically.
Now, let’s go through the steps to use Laravel Horizon to monitor queues.
Step 1: Install Laravel Horizon
The first step is to install Laravel Horizon into your Laravel application. If you haven’t already installed Laravel Horizon, follow these steps:
- Install Horizon via Composer: Open your terminal and navigate to the root directory of your Laravel project. Run the following command:bashCopyEdit
composer require laravel/horizon
- Publish Horizon’s Assets: After installing Horizon, you need to publish its configuration files. Run the following command:bashCopyEdit
php artisan horizon:install
This command will create the necessary configuration files and assets required for Horizon to work. - Run Migrations: Horizon stores information about your queues in a database. You need to run the migrations to set up the required tables. Run:bashCopyEdit
php artisan migrate
After completing these steps, Horizon will be installed and ready to use.
Step 2: Configure Your Queue Driver
Laravel Horizon works with Laravel’s queue system, so you need to make sure your queues are configured correctly. Laravel supports several queue drivers, including Redis, Database, and SQS.
- Choose a Queue Driver: In your
.env
file, choose a queue driver. For Horizon, Redis is the recommended queue driver. Make sure you set it up like this:dotenvCopyEditQUEUE_CONNECTION=redis
- Configure Redis: If you’re using Redis, make sure your
config/database.php
file is configured correctly for Redis. You’ll find the Redis configuration in theconnections
array.Example Redis configuration:phpCopyEdit'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', '6379'), 'database' => env('REDIS_DB', '0'), ], ],
- Restart Queue Worker: After configuring the queue driver, restart your queue workers so they can start processing jobs. Run the following command:bashCopyEdit
php artisan queue:work
Step 3: Access the Horizon Dashboard
Once you have Horizon installed and your queue driver configured, it’s time to access the Horizon dashboard.
- Start the Laravel Development Server: If you’re working locally, you can start Laravel’s built-in server by running:bashCopyEdit
php artisan serve
- Access the Dashboard: Once the server is running, open your browser and navigate to the following URL:arduinoCopyEdit
http://127.0.0.1/horizon
The Horizon dashboard should now be accessible. You’ll be able to see all the queues, job metrics, and more.
Step 4: Monitor Job Metrics
Laravel Horizon provides a real-time dashboard that shows key metrics for your queues, including:
- Job Throughput: The number of jobs processed per minute.
- Job Failures: The total number of failed jobs.
- Job Time: The execution time of each job.
- Wait Time: The amount of time jobs spend in the queue before being processed.
The dashboard displays these metrics for each queue, allowing you to monitor the health and performance of your background tasks. You can see trends and identify any bottlenecks or issues in your job processing.
Step 5: Retry Failed Jobs
Sometimes jobs fail due to temporary issues (e.g., a network failure or an external service being unavailable). Laravel Horizon allows you to easily retry failed jobs.
- View Failed Jobs: In the Horizon dashboard, navigate to the “Failed Jobs” section. This will display all jobs that have failed.
- Retry Jobs: You can manually retry failed jobs by clicking the “Retry” button next to each job. Alternatively, you can retry all failed jobs at once.
- Configure Auto-Retry: You can also configure Horizon to automatically retry failed jobs after a certain amount of time. To do this, go to the
config/horizon.php
file and adjust theretry_after
setting.
Step 6: Configure Queue Workers
Laravel Horizon provides an easy way to manage and configure your queue workers. You can configure different types of workers for different queues.
- Edit Worker Configurations: Open the
config/horizon.php
file. Here, you can configure settings like the number of workers per queue, memory limits, and the timeout settings. - Set Up Supervisor: Horizon works well with Supervisor, a process monitor that can automatically restart your workers if they fail. To set up Supervisor, install it on your server and configure it to run the Laravel Horizon process.Example Supervisor configuration for Horizon:iniCopyEdit
[program:horizon] process_name=%(program_name)s command=php /path/to/your/project/artisan horizon autostart=true autorestart=true user=youruser numprocs=1 redirect_stderr=true stdout_logfile=/path/to/your/project/storage/logs/horizon.log
Step 7: Optimize Horizon Performance
To ensure that Horizon works efficiently, you can optimize its performance by adjusting various settings.
- Use Redis Clustering: If you’re running a large-scale application, consider using Redis clustering for better performance and fault tolerance.
- Tune Horizon’s Metrics Collection: Horizon collects a lot of metrics. If you’re monitoring many queues, you might want to fine-tune how often Horizon collects these metrics. You can adjust the polling frequency in the
config/horizon.php
file. - Cache Configuration: Horizon relies on Redis for storing metrics and job statuses. Ensure that Redis is properly configured and optimized for production environments.
Conclusion
Laravel Horizon is an invaluable tool for monitoring and managing queues in Laravel applications. By following these 7 easy steps, you can easily set up and start using Horizon to track job performance, retry failed jobs, and configure queue workers. Horizon’s real-time dashboard and powerful metrics will help you ensure that your background jobs are running smoothly and efficiently.
If you’re working with Laravel queues, don’t forget to install and configure Horizon—it’s a must-have tool for any Laravel developer.