The Complete Production SOP: How to Deploy and Run Laravel Horizon Redis Queue Management & Metrics in Autonomous AI Agents
Step-by-step SOP to install and run Laravel Horizon Redis Queue Management in Codex, Claude Code, & Cursor. Includes balance configs, gates, and troubleshooting.
Technical Overview & Architectural Context
Autonomous coding agents frequently stumble when provisioning asynchronous queue architectures in Laravel. Common hallucinations include mixing classical `php artisan queue:work` daemon commands with Horizon supervisors, misconfiguring Redis connection prefixes causing key collisions, hardcoding balance strategies that starve high-priority queues, and neglecting strict dashboard authorization gates in `HorizonServiceProvider`. Without a deterministic operational framework, agents often leave queue workers unmonitored or spawn unbounded child processes that trigger memory exhausted panics in production. The `laravel-queues-horizon-monitoring` skill enforces strict architectural boundaries across the agent's reasoning loop. It mandates deterministic declarative configuration inside `config/horizon.php`, enforces process scaling ceilings with minimum and maximum thresholds, verifies Redis connection isolation, and guarantees that access gates rely on role-based authentication rather than permissive development bypasses. By codifying these runtime constraints, autonomous agents deliver reproducible, production-grade queue pipelines that reliably survive deployments.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the laravel-queues-horizon-monitoring rule manifest to your workspace or user agent directory.
Autonomous agents read dynamic rules from predefined discovery directories (`.agents/skills` or `.cursor/rules`). Mounting the skill injects the required Horizon operational boundaries, ensuring the agent executes the installation and configuration deterministically without asking for shell elevation unless required.
mkdir -p .agents/skills/laravel-queues-horizon-monitoring && curl -fsSL https://askills.dev/api/skills/laravel-queues-horizon-monitoring/raw -o .agents/skills/laravel-queues-horizon-monitoring/SKILL.md---
name: "laravel-queues-horizon-monitoring"
description: "Manage and monitor Redis queues in Laravel with real-time throughput metrics and auto-scaling."
metadata:
author: "Laravel"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "setup laravel horizon"
- "auto balance horizon workers"
- "retry failed jobs horizon"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: false
---Place the file directly inside `.cursor/rules/horizon.mdc` or `.claude/skills/horizon.md` for zero-configuration automatic context indexing.
Ensure `pcntl` and `posix` extensions are enabled in your CLI PHP interpreter; Horizon requires process control and cannot run on Windows environments natively without WSL2.
Composer Package Installation & Provider Publication
Instruct the agent to install Laravel Horizon via Composer and publish application assets and configuration.
The agent validates dependencies and executes package registration. This creates `config/horizon.php` and registers `App\Providers\HorizonServiceProvider` in bootstrap configurations without polluting git status with transient cache files.
composer require laravel/horizon && php artisan horizon:install && php artisan vendor:publish --tag=horizon-configEnsure `QUEUE_CONNECTION=redis` is configured in `.env` before publishing to prevent fallback to sync queue drivers during artisan boot.
Do not skip publishing assets in CI/CD pipelines; Horizon web dashboard static assets must exist in `public/vendor/horizon`.
Dynamic Worker Pool & Balancing Configuration
Configure config/horizon.php with auto-balancing, min/max worker boundaries, and queue priorities.
The skill instructs the agent to configure production supervisor workers to use dynamic balancing. It defines queue priorities (e.g., `high`, `default`, `notifications`) and bounds process limits to avoid starving system memory.
return [
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['high', 'default', 'low'],
'balance' => 'auto',
'autoScalingStrategy' => 'time',
'minProcesses' => 2,
'maxProcesses' => 16,
'balanceMaxShift' => 2,
'balanceCooldown' => 3,
'memory' => 128,
'tries' => 3,
'timeout' => 60,
'nice' => 0,
],
],
],
];Setting `autoScalingStrategy => 'time'` scales processes based on the estimated time to clear queues rather than raw job count, preventing long-running job starvation.
Never set `minProcesses` to 0 on critical queues unless you tolerate cold-start latencies when bursts of jobs arrive.
Gate Authorization & Metrics Verification Gate
Lock down dashboard access in HorizonServiceProvider and run self-validating test assertions.
The skill enforces zero-trust access control by modifying `app/Providers/HorizonServiceProvider.php`. The agent configures explicit authorization callbacks and executes test commands to verify configuration validity before reporting task completion.
php artisan config:cache && php artisan horizon:check && php artisan test --filter=HorizonTestnamespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Laravel\Horizon\HorizonApplicationServiceProvider;
class HorizonServiceProvider extends HorizonApplicationServiceProvider
{
protected function gate(): void
{
Gate::define('viewHorizon', function ($user) {
return in_array($user->email, config('horizon.allowed_admins', []))
|| $user->tokenCan('admin:horizon');
});
}
}Mock `Gate::allows('viewHorizon')` in Feature tests to guarantee unauthorized requests receive HTTP 403 Forbidden.
In local environments, Horizon defaults to allowing all access; ensure environment checks explicitly disallow public exposure when `APP_ENV=production`.
Real-World Scenario: Autonomous Configuration of Dynamic Queue Balancing with Secure Dashboard Access
“Set up Laravel Horizon on this project. Configure production workers with auto-balancing for 'high' and 'default' queues, capped at 12 processes. Secure the dashboard to only allow users with the 'admin' role, and verify with a test.”
Runtime Troubleshooting & Failure Modes
Root Cause: The master supervisor process died, the Redis connection prefix differs between web and worker processes, or Horizon was deployed without terminating old processes.
php artisan horizon:terminate && php artisan horizon:purge && php artisan horizonRoot Cause: Queued jobs exceed the `timeout` directive declared in `config/horizon.php` while Horizon supervisor attempts graceful termination.
Update `config/horizon.php` to increase `'timeout' => 300` or specify `$timeout = 300;` on the specific job class, and run `php artisan horizon:terminate`.Frequently Asked Questions (Laravel Horizon Redis Queue Management & Metrics SOP)
Q:Can I use Laravel Horizon Redis Queue Management & Metrics across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. By placing it in `.agents/skills/laravel-queues-horizon-monitoring` or linking it in `.cursor/rules` and `.claude/skills`, all runtimes parse identical triggers and constraints.
Q:How does this skill prevent context window overflow during long agent sessions?
It provides concise, deterministic step rules and concrete code samples instead of dumping verbose framework documentation, preserving high-value context tokens for application-specific logic.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within normal user-level workspace boundaries without modifying system packages or host network configs.
Ready to equip your autonomous agent with Laravel Horizon Redis Queue Management & Metrics?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.