Use it for every modern PHP deployment behind nginx or Apache event MPM; size pools to memory, isolate sites in separate pools and users, and read its status page when PHP pages slow down or return 502/504.
PHP-FPM
PHP-FPM (FastCGI Process Manager) runs PHP as a pool of worker processes that a web server (nginx, Apache, Caddy) talks to over FastCGI on a Unix socket or TCP port.
1. Is FPM running and listening where the web server expects (socket path/port)?
2. Can the web server user access the socket?
3. Is the pool at max children with a listen queue?
4. Are slow requests in the slowlog (database, external API)?
web server location → fastcgi_pass (socket/TCP) → FPM pool listen queue → worker process (pm) → PHP script → response → web server
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
systemctl status php8.2-fpmVerification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Read-only Verification Verify boundary
# Service and configuration
systemctl status php8.2-fpm
php-fpm8.2 -t
# Is the socket there, and who may use it?
ls -l /run/php/
# Status page through the web server (location restricted to localhost)
curl -s 'http://127.0.0.1/fpm-status?full' | head -20
# Pool exhaustion and slow requests
grep -i 'max_children' /var/log/php8.2-fpm.log | tail
tail -n 50 /var/log/php-fpm/shop-slow.log
listen queue above 0 or a rising max children reached means the pool is too small for the load or requests are too slow; the slowlog's PHP backtraces show which function was running (often a database call or an external HTTP request).
Step 2 Common mistakes Narrow the fault
- One shared pool and user for every site.
- Setting
pm.max_childrenfar above what memory can hold. - Exposing FastCGI on a TCP port to the network.
- Passing every URL ending in
.phpto FPM without checking that the file exists. - Leaving the status page public.
Step 3 Troubleshooting Narrow the fault
502 Bad Gateway, error log: connect() to unix:/run/php/... failed (2: No such file or directory). FPM is stopped, the pool failed to start, or the socket path differs between FPM and the web server (often after a PHP version upgrade: php8.1 → php8.2 socket name).
502 with (13: Permission denied). The web server user cannot access the socket; fix listen.owner/group/mode.
504 Gateway Timeout / upstream timed out. Workers are busy or a script is slow. Check status (queue, max children) and the slowlog.
Log says server reached pm.max_children setting. Raise pm.max_children only if memory allows; otherwise fix slow requests or add capacity.
"File not found." or "Primary script unknown". Wrong SCRIPT_FILENAME (document root mismatch) or the pool user cannot read the file.
pm.max_children caps concurrent PHP requests — when it is reached, requests queue and the log says 'server reached pm.max_children'. 502 = web server could not talk to FPM (socket missing, permissions, FPM down); 504 = FPM accepted but answered too slowly. Never expose the FastCGI port publicly.
systemctl status php8.2-fpm(name varies by distro/version) — running, pools.php-fpm8.2 -t— configuration test.- Status page (
pm.status_path = /status) — active/idle processes, listen queue, max children reached, slow requests. grep -i 'max_children' /var/log/php8.2-fpm.log— pool exhaustion.- Web server error log: 'connect() to unix:/run/php/... failed' or 'upstream timed out'.
ReferenceWhat it is2 sections · depth on demand
Direct Answer
PHP-FPM runs PHP in pools of worker processes. The web server does not execute PHP itself: it forwards each PHP request over FastCGI to a pool's socket, a free worker runs the script, and the result goes back to the web server. The process manager (pm) decides how many workers exist — static, dynamic or ondemand — and pm.max_children is the hard cap on concurrent PHP requests. Most PHP outages are either the web server failing to reach the socket (502) or a pool that is full or slow (504).
Scope and canonical references
- Web servers in front of it: Nginx, Apache, Caddy.
- Site separation: Virtual Hosts.
- Diagnosing the full request path: Web Server Troubleshooting, HTTP.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Pools
Each pool ([www], [shop]…) has its own user/group, listen socket, process-manager settings and PHP overrides (php_admin_value[...]). One pool per site isolates file permissions, resource use and crashes.
Process manager
pm | Behaviour | Main directives |
|---|---|---|
static | Fixed number of workers | pm.max_children |
dynamic | Between spare limits, up to the maximum | pm.max_children, pm.start_servers, pm.min_spare_servers, pm.max_spare_servers |
ondemand | Spawns on request, kills idle workers | pm.max_children, pm.process_idle_timeout (default 10 s) |
pm.max_requests recycles a worker after N requests (0 = never), a workaround for memory leaks.
Sizing
Measure the resident memory of a typical worker under load (ps -o rss -C php-fpm8.2) and set pm.max_children to roughly *(RAM available for PHP) ÷ (average worker RSS)*, leaving room for the database, web server and page cache. More workers than CPU and memory can serve only moves the queue into swap.
Socket and permissions
[shop]
user = shop
group = shop
listen = /run/php/php8.2-fpm-shop.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
pm.status_path = /fpm-status
ping.path = /fpm-ping
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/shop-slow.log
request_terminate_timeout = 120s
The web server user needs read/write on the socket. For TCP listeners, set listen.allowed_clients and never publish the port: an exposed FastCGI endpoint allows arbitrary code execution.
Web server side (nginx)
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.2-fpm-shop.sock;
fastcgi_read_timeout 120s;
}
try_files $uri =404 prevents nginx from passing non-existent paths (for example an uploaded image with /x.php appended) to PHP. Apache uses mod_proxy_fcgi with SetHandler "proxy:unix:/run/php/php8.2-fpm-shop.sock|fcgi://localhost".
Timeouts
Three limits interact: PHP's max_execution_time, FPM's request_terminate_timeout (kills the worker, also when PHP's limit does not apply), and the web server's fastcgi_read_timeout (default 60 s in nginx). Keep the web server timeout at least as long as the longest legitimate request, and use the slowlog to find what is slow.
Status page fields
| Field | Meaning |
|---|---|
| accepted conn | Requests accepted since start |
| listen queue | Requests waiting for a free worker — should be 0 |
| max listen queue | Highest queue since start |
| idle / active processes | Current workers |
| max active processes | Peak concurrency |
| max children reached | Times the pool hit pm.max_children |
| slow requests | Requests over request_slowlog_timeout |
Protect the status and ping paths so only localhost or monitoring can reach them. pm.status_listen (PHP 8.0+) serves status from a separate listener that stays reachable when the pool is busy.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.