{
    "slug": "php_queue_workers",
    "term": "PHP Queue Workers",
    "category": "messaging",
    "difficulty": "intermediate",
    "short": "Laravel Horizon for Redis queues with dashboard and auto-scaling; Supervisor for process management ensuring crashed workers automatically restart.",
    "long": "PHP queue workers process jobs from queues (Redis, SQS, database) in persistent background processes. Laravel Horizon: dashboard with real-time metrics, auto-scaling worker pools, per-queue configuration, memory limit enforcement. Supervisor: process control system that monitors and restarts crashed workers, manages multiple worker processes with log rotation. Job patterns: $tries and $backoff for retry logic, failed() hook for cleanup on permanent failure, ShouldBeUnique for deduplication.",
    "aliases": [
        "Laravel Horizon",
        "Supervisor",
        "queue worker",
        "background jobs",
        "php artisan queue:work"
    ],
    "tags": [
        "messaging",
        "php",
        "devops"
    ],
    "misconception": "Queue workers restart automatically when they crash — without Supervisor or systemd, a crashed worker process simply stops; the queue silently backs up until someone notices and restarts manually.",
    "why_it_matters": "Processing 1000 emails synchronously in a web request blocks users for minutes — queue workers process them asynchronously in the background, and Supervisor automatically restarts any worker that crashes.",
    "common_mistakes": [
        "Workers started manually without Supervisor — crashed workers never restart",
        "No memory limit — PHP workers accumulate memory leaks over time without restart",
        "No job timeout — a hanging job blocks that worker indefinitely",
        "Single worker handling all job types — slow report generation blocks fast email sending"
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "message_queue_patterns",
        "at_least_once_delivery",
        "systemd_services",
        "queue_based_load_levelling"
    ],
    "prerequisites": [
        "async_processing",
        "message_queue_patterns",
        "php_fpm"
    ],
    "refs": [
        "https://laravel.com/docs/horizon"
    ],
    "bad_code": "# Manual worker without process management:\nphp artisan queue:work &\n# Worker crashes: nobody notices\n# Queue backs up silently\n# Server restarts: worker never comes back\n# 2 hours later: customer reports emails not sending",
    "good_code": "# /etc/supervisor/conf.d/horizon.conf:\n[program:horizon]\nprocess_name=%(program_name)s\ncommand=php /var/www/app/artisan horizon\nautostart=true\nautorestart=true\nuser=www-data\nstopwaitsecs=3600\nstdout_logfile=/var/log/supervisor/horizon.log\n\n# config/horizon.php — separate queues, memory limits:\n# 'supervisor-1' => ['queue'=>['critical','default','low'],'processes'=>10,'memory'=>128]",
    "quick_fix": "Configure Laravel Horizon or Symfony Messenger workers with supervisor/systemd — set max-tries=3 and a timeout, and always have a dead-letter queue for failed jobs",
    "severity": "high",
    "effort": "medium",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_queue_workers",
        "html_url": "https://codeclaritylab.com/glossary/php_queue_workers",
        "json_url": "https://codeclaritylab.com/glossary/php_queue_workers.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[PHP Queue Workers](https://codeclaritylab.com/glossary/php_queue_workers) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_queue_workers"
            }
        }
    }
}