laravel/horizon
Laravel Horizon adds a polished dashboard and code-driven configuration for Laravel Redis queues. Monitor job throughput, runtime, failures, and worker status, with all queue worker settings kept in a single config file for easy version control.
Laravel Horizon is a first-class fit for Laravel-based applications relying on Redis queues (e.g., redis, database drivers are unsupported). It replaces Laravel’s default queue worker with a supervisor-based system, enabling:
config/horizon.php.supervisor.json).Key architectural benefits:
Anti-patterns to avoid:
laravel-queue-worker exist for other drivers.Prerequisites:
queue:work falls back to CLI workers in dev).Integration steps:
composer require laravel/horizon
php artisan horizon:install
config/horizon.php (e.g., set supervisor to true, define concurrency, batch sizes)..env (e.g., REDIS_URL=redis://redis:6379)./etc/supervisor/conf.d/horizon.conf (example provided in Horizon docs).supervisorctl reread && supervisorctl update && supervisorctl start horizon:*.Compatibility:
database/sync (Redis-only).Illuminate\Bus\Queueable (standard for Laravel jobs).dispatchAfterCommit, onQueue, etc.Potential conflicts:
redis-cli --stat).| Risk Area | Severity | Mitigation |
|---|---|---|
| Redis dependency | High | Ensure Redis is hardened (persistence, eviction policies). |
| Supervisor misconfig | Medium | Test with supervisorctl status before production rollout. |
| Job timeouts | Medium | Configure timeout in horizon.php (default: 60s) and monitor long-running jobs. |
| Dashboard latency | Low | Use Redis clustering for high-throughput queues. |
| PHP version skew | Low | Horizon supports PHP 8.1–8.5; align with Laravel’s requirements. |
Critical questions for the TPM:
queue:work as a backup.Horizon is optimized for:
Stack compatibility:
| Component | Compatibility |
|---|---|
| Laravel | 9.x–12.x (with minor version quirks; check changelog for PHP 8.5+ fixes). |
| Redis | 6.x+ (tested with StackExchange Redis, AWS ElastiCache). |
| Supervisor | 4.x+ (required for production; dev uses horizon:listen). |
| Database | Agnostic (but job payloads must serialize to Redis). |
| Monitoring | Integrates with Prometheus (via horizon:metrics), Datadog, etc. |
Non-compatible stacks:
laravel-queue-worker or pestle instead.Phase 1: Pilot (Dev/Staging)
queue:work:
pkill -f queue:work.php artisan horizon.queue:work --daemon.concurrency, batch, and timeout in horizon.php.Phase 2: Production Rollout
/etc/supervisor/conf.d/horizon.conf (example below):
[program:horizon-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan horizon:work
autostart=true
autorestart=true
numprocs=8
user=www-data
numproc=8
supervisorctl reread && supervisorctl update.supervisorctl tail -f horizon-worker stdout for logs.Phase 3: Optimization
numprocs based on CPU/memory usage.batch size for high-volume queues (e.g., batch:100).| Feature | Compatibility Notes |
|---|---|
| Job Middleware | Fully supported (e.g., dispatchAfterCommit). |
| Delayed Jobs | Works with delay() and afterCommit(). |
| Job Batching | Native support via batch() method. |
| Custom Workers | Extend Illuminate\Queue\WorkerOptions for advanced use cases. |
| Queue Retries | Configurable via maxAttempts and backoff in horizon.php. |
| Laravel Events | Triggers job.processed, job.failed, etc. (listen via Horizon::onEvent). |
Known limitations:
Recommended order:
queue:work from deployment scripts.Rollback plan:
queue:work in CI/CD until Horizon is stable.php artisan queue:flush to clear Horizon-managed queues if needed.Pros:
horizon.php (version-controlled).supervisorctl.Cons:
maxmemory-policy).How can I help you explore Laravel packages today?