ralphjsmit/laravel-horizon-cron-supervisor

A modern solution for running Laravel Horizon with a CRON-based supervisor.
12,150 63
Install
composer require ralphjsmit/laravel-horizon-cron-supervisor
Latest Version:1.4.3
Laravel:8 – 12
License:MIT
Last Updated:Mar 17, 2025
Links: GitHub  ·  Packagist
Maintainer: ralphjsmit

laravel-horizon-cron-supervisor@2x

A modern solution for running Laravel Horizon with a cron-based supervisor

Run Laravel Horizon on cheap hosting environments without Supervisor🤑

This Laravel package automatically checks every three minutes if your Laravel Horizon instance is still running. In that way, it is the perfect replacement for the normally recommended Supervisor Process Control System, for which you need your own server.

This package allows running Laravel Horizon on shared hosting instances and servers where you don't have to option to install Supervisor.

Under the hood, the package automatically schedules a simple Artisan command to run every three minutes that checks whether Horizon is still running. If not, it'll restart the Horizon queues.

Installation

Run the following command to install the package:

composer require ralphjsmit/laravel-horizon-cron-supervisor

The package works without any configuration. Note that you need to have the Laravel Scheduler configured correctly.

Publishing the config file

You can publish the config file or just use the environment variables.

php artisan vendor:publish --tag="horizon-cron-supervisor-config"

The config file contents.

<?php

return [
    /**
     * Enables Horizon Cron Supervisor
     */
    'enabled' => env('HORIZON_CRON_SUPERVISOR_ENABLED', true),

    /**
     * Run every X minutes or define a cron expression like "0,20,40 * * * *"
     */
    'schedule' => env('HORIZON_CRON_SUPERVISOR_SCHEDULE', 3),
];

How does this work with new deployments?

When you deploy a new version of your app, you usually shut down your queues and Horizon instances in order let them use the files. The Laravel Scheduler doesn't run any commands when your application is in maintenance mode (php artisan down). Thus as long as your application is in maintenance mode, you don't need to worry about this package restarting your queues when you don't want that.

A typical deployment workflow could look something like this:

# Prepare deployment 

php artisan down
php artisan horizon:terminate

# Do deployment logic
# Horizon will not be restarted until you put the application out of maintenance mode

php artisan horizon
php artisan up

# Finish up deployment

Note that this workflow is greatly simplified and doesn't take into account anything specific to your server or running commands like your migrations.

About the package

This package was created by Ralph J. Smit. Checkout my website ralphjsmit.com for Laravel and development-related tutorials.

The package was inspired by this StackOverflow question and my need for this as well. Special thanks to ahoffman for his code on running and checking whether Horizon is active.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released Laravel License
1.4.3 ^8.0|^9.0|^10.0|^11.0|^12.0 MIT
1.4.2 ^8.0|^9.0|^10.0|^11.0 MIT
1.4.1 ^8.0|^9.0|^10.0|^11.0 MIT
1.4.0 ^8.0|^9.0|^10.0|^11.0 MIT
1.3.0 ^8.0|^9.0|^10.0|^11.0 MIT