{
    "slug": "php_fpm",
    "term": "PHP-FPM",
    "category": "php",
    "difficulty": "intermediate",
    "short": "PHP FastCGI Process Manager — a high-performance PHP process manager that manages worker pools for web servers like Nginx.",
    "long": "PHP-FPM (FastCGI Process Manager) runs PHP as a separate service communicating with the web server (typically Nginx) via FastCGI. It manages a pool of PHP worker processes, restarting crashed workers, and supports dynamic/static/ondemand process management strategies. Key configuration includes pm.max_children (limits concurrency and memory), request_terminate_timeout (prevents runaway processes), and slowlog (identifies slow scripts). Unlike Apache mod_php, PHP-FPM isolates PHP execution from the web server, improving security and allowing different pools per virtual host.",
    "aliases": [
        "PHP-FPM",
        "FastCGI Process Manager",
        "PHP process manager"
    ],
    "tags": [
        "php",
        "devops",
        "server",
        "performance"
    ],
    "misconception": "PHP-FPM pool configuration is a set-and-forget server setting. Pool configuration — pm.max_children, pm.start_servers, and pm.max_requests — directly affects memory usage, concurrency, and the frequency of memory leak mitigation. It should be tuned to the specific application and server resources.",
    "why_it_matters": "PHP-FPM manages a pool of PHP worker processes — correct pool sizing and timeout configuration directly determines throughput, memory usage, and behaviour under load.",
    "common_mistakes": [
        "Using the default pm = dynamic settings without tuning for your application's memory per worker.",
        "Setting pm.max_children too high — workers exceed available RAM and the server starts swapping.",
        "Not setting request_terminate_timeout — runaway scripts hold workers indefinitely, starving new requests.",
        "Not monitoring the PHP-FPM slow log — slow requests are invisible without it."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "opcache",
        "php_ini"
    ],
    "prerequisites": [
        "nginx_php_fpm_config",
        "opcache",
        "connection_pooling"
    ],
    "refs": [
        "https://www.php.net/manual/en/install.fpm.php",
        "https://www.php.net/manual/en/install.fpm.configuration.php"
    ],
    "bad_code": "# php-fpm pool.conf — untuned defaults:\npm = dynamic\npm.max_children = 50        ; Too high if each worker uses 100MB — that's 5GB RAM\npm.start_servers = 5\npm.min_spare_servers = 5\npm.max_spare_servers = 35\n; request_terminate_timeout = 0 — infinite by default, runaway scripts block workers",
    "good_code": "; /etc/php/8.3/fpm/pool.d/www.conf\n[www]\nuser  = www-data\ngroup = www-data\npm                   = dynamic\npm.max_children      = 50     ; workers x memory < available RAM\npm.start_servers     = 5\npm.min_spare_servers = 2\npm.max_spare_servers = 10\npm.max_requests      = 500    ; recycle to prevent memory leaks\n\nrequest_slowlog_timeout = 5s\nslowlog = /var/log/php-fpm/slow.log\npm.status_path = /fpm-status\n\nchdir = /var/www/app\nphp_admin_value[open_basedir] = /var/www/app:/tmp\nphp_admin_value[disable_functions] = exec,system,shell_exec",
    "quick_fix": "Set pm=dynamic, pm.max_children = (RAM - 512MB) / avg_worker_MB, pm.max_requests=500 to prevent memory leaks accumulating indefinitely",
    "severity": "high",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_fpm",
        "html_url": "https://codeclaritylab.com/glossary/php_fpm",
        "json_url": "https://codeclaritylab.com/glossary/php_fpm.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-FPM](https://codeclaritylab.com/glossary/php_fpm) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_fpm"
            }
        }
    }
}