Overview
PHP-FPM manages PHP worker processes for web servers such as Nginx and Apache configurations that use FastCGI. Its settings affect concurrency, memory use and request handling. Increasing worker counts without measuring memory can make an overloaded server less stable.
Understand the process manager
PHP-FPM supports static, dynamic and ondemand process management modes. Static keeps a fixed number of workers. Dynamic adjusts the pool within configured limits. Ondemand starts workers as requests arrive and can suit low-traffic environments, though startup behavior should be measured.
Estimate worker capacity
Measure the typical and peak memory footprint of PHP workers under realistic requests. A rough upper bound is:
available PHP memory budget / measured worker memory
Reserve memory for the operating system, database, web server, caches and other services. Do not use the server's total RAM as the PHP pool budget.
Observe the pool
Enable the FPM status endpoint but restrict it to trusted monitoring access. Watch active and idle processes, listen queue, max children reached and slow requests. These signals are more useful than guessing a worker count.
Slow request logging
Configure a slow log threshold to capture stack traces for requests that exceed an expected duration. Use it to identify slow database calls, external HTTP requests or expensive application code. Protect log files because traces can contain paths and sensitive context.
Change one setting at a time
Tune pm.max_children, spare server limits and request recycling only after collecting measurements. pm.max_requests can help recycle workers in environments where memory growth is observed, but it is not a substitute for fixing leaks.
Checklist
- Measure worker memory under realistic load.
- Reserve memory for the rest of the server.
- Choose process manager mode deliberately.
- Monitor queue depth and max-children events.
- Restrict FPM status and slow-log access.
- Change settings gradually and compare metrics.