fabianpnke / horizon-db-driver
A database storage and queue driver for Laravel Horizon, for running Horizon without Redis.
Fund package maintenance!
Requires
- php: ^8.0
- illuminate/contracts: ^9.21|^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^9.21|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.21|^10.0|^11.0|^12.0|^13.0
- laravel/horizon: ^5.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pao: ^1.0
- laravel/pint: ^1.29
- orchestra/testbench: ^7.56||^8.37||^9.16||^10.9||^11.0
- pestphp/pest: ^4.6
- pestphp/pest-plugin-laravel: ^4.1
- pestphp/pest-plugin-type-coverage: ^4.0
- phpstan/extension-installer: ^1.4
- phpunit/phpunit: ^9.6||^10.0||^11.0||^12.0
README
Horizon Db Driver
A database storage driver for Laravel Horizon, for teams that want Horizon's dashboard and job-monitoring workflow without running Redis. It swaps Horizon's Redis-backed lock, repositories, and command queue for SQL-table-backed equivalents, and registers a database queue connector that emits the same Horizon events the Redis connector does.
This package does not fork or modify Horizon — it requires the official laravel/horizon package and layers a second service provider on top that rebinds the relevant container singletons after Horizon's own provider has registered them.
📚 Full documentation is available at https://fabianpnke.github.io/horizon-db-driver/.
Origin
All of the database driver logic in this package — the repositories, the lock, the command queue, the queue connector, the migration — is Steve Bauman's work from laravel/horizon#1762, a pull request against Horizon itself. Taylor Otwell closed it with:
While I respect the effort and the idea, I don't personally want to be responsible for maintaining a DB version of Horizon right now. I think it could be a cool community package / fork though!
This package is that community package: Steve's implementation adapted to run alongside the official laravel/horizon package via container bindings, instead of as a fork of it.
Installation
You can install the package via Composer:
composer require fabianpnke/horizon-db-driver
This package requires laravel/horizon to already be installed and configured (see Horizon's own installation docs).
Publish and run the migrations:
php artisan vendor:publish --tag="horizon-db-driver-migrations"
php artisan migrate
The migration creates the horizon_jobs, horizon_tags, horizon_monitored_tags, horizon_supervisors, horizon_master_supervisors, horizon_processes, horizon_metrics, horizon_metric_snapshots, horizon_metric_meta, horizon_command_queue, and horizon_locks tables.
You may also publish the config file:
php artisan vendor:publish --tag="horizon-db-driver-config"
Usage
Once installed, the package is active by default — Horizon's Redis-backed lock, repositories, and command queue are replaced with database-backed implementations, and a database queue connector is registered.
Point at least one of your config/queue.php connections at that connector so Horizon has jobs to work:
'connections' => [ 'database' => [ 'driver' => 'database', 'table' => 'jobs', 'queue' => 'default', 'retry_after' => 90, ], ],
Note: enabling this package makes every queue connection configured with driver
database— not just the one(s) Horizon supervises — emit Horizon's job lifecycle events. This matches the upstreamdatabaseconnector name so behavior is a drop-in replacement, but it does mean a plain, non-Horizondatabasequeue connection in the same app will also start showing up in Horizon's dashboard.
No Horizon config changes are required — this package doesn't read Horizon's own config/horizon.php, it activates based on its own enabled flag (default true). To turn it off per-environment without removing the package:
HORIZON_DB_DRIVER_ENABLED=false
By default the package uses your application's default database connection. To point it at a different one:
HORIZON_DB_DRIVER_CONNECTION=horizon
Notes when switching from Redis
Horizon itself still assumes a few Redis-specific defaults, independent of which storage driver is active:
config('horizon.waits')keys are formatted"{connection}:{queue}"and default toredis:default. Add an entry keyed with your database queue connection's name (e.g.database:default) if you want accurate "long wait detected" notifications.- The published
config/horizon.phpstub hardcodes'connection' => 'redis'underdefaults.supervisor-1. Change it to your database queue connection's name so your supervisors actually work the right queue. - Horizon's own service provider unconditionally calls
Horizon::use()on boot, which expectsconfig('database.redis.{connection}')to exist and throws if it's missing — even though this package never touches Redis. Most Laravel apps ship with a default Redis connection block already, so this is rarely an issue in practice, but if your app has removed it entirely, Horizon won't boot regardless of which driver you're using.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Thank you for considering contributing to Horizon Db Driver! Please review our contributing guide to get started.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Steve Bauman — original author of the database driver implementation this package is built on, from laravel/horizon#1762
- fabianpnke
- All Contributors
License
Horizon Db Driver is open-sourced software licensed under the MIT license.