Posts Learn Components Snippets Categories Tags Tools new About
/

Getting Started With Laravel Horizon

Let's get started with setting up Laravel Horizon to monitor Redis Queue

Created on Sep 15, 2021

53 views

In this short snippet, you will learn how to get started with Laravel Horizon the easy way.

A little bit of Laravel Horizon

Laravel Horizon provides a beautiful dashboard and code-driven configuration for your Laravel powered Redis queues. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures.

Install Laravel Horizon and Publishing Configuration


To install Laravel Horizon you can make use of the composer package manager by running the command below.
composer require laravel/horizon
Do note that depending on your Laravel version you will have to see which Horizon version you have to install since by default it will install the latest version available for the latest Laravel application.
Now that it's installed you need to publish the assets provided by Horizon. This step is necessary and you can't skip.
php artisan horizon:install
Laravel horizon comes with a predefined configuration but you can update it through the configuration file that's included.
config/horizon.php

Laravel Horizon Configuration


Below is the horizon configuration that comes by default. We do recommend that you change domain and path if necessary as this will help to better secure your application from users that may attempt to access it.
<?php

use Illuminate\Support\Str;

return [

    'domain' => env('HORIZON_DOMAIN', null),

    'path' => env('HORIZON_PATH', 'horizon'),

    'use' => 'default',

    'prefix' => env(
        'HORIZON_PREFIX',
        Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
    ),

    'middleware' => ['web'],

    'waits' => [
        'redis:default' => 60,
    ],

    'trim' => [
        'recent' => 60,
        'pending' => 60,
        'completed' => 60,
        'recent_failed' => 10080,
        'failed' => 10080,
        'monitored' => 10080,
    ],

    'metrics' => [
        'trim_snapshots' => [
            'job' => 24,
            'queue' => 24,
        ],
    ],

    'fast_termination' => false,

    'memory_limit' => 64,

    'defaults' => [
        'supervisor-1' => [
            'connection' => 'redis',
            'queue' => ['default'],
            'balance' => 'auto',
            'maxProcesses' => 1,
            'memory' => 128,
            'tries' => 1,
            'nice' => 0,
        ],
    ],

    'environments' => [
        'production' => [
            'supervisor-1' => [
                'maxProcesses' => 10,
                'balanceMaxShift' => 1,
                'balanceCooldown' => 3,
            ],
        ],

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

Laravel Horizon Pause and Continue Process


You can "pause" and "continue" process in Laravel horizon by running the command below.
php artisan horizon:pause

php artisan horizon:continue
If you do want to specify the supervisor then you can specify the supervisor name.
php artisan horizon:pause-supervisor supervisor-1

php artisan horizon:continue-supervisor supervisor-1
Terminating horizon can be done using the terminate command.
php artisan horizon:terminate

Upgrading Laravel Horizon


You can upgrade Laravel Horizon normally using composer update and once you have done so do run the "horizon:publish" command as it's necessary to update the published assets.
php artisan horizon:publish

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Getting Started With Laravel Horizon

)