Independent comparison · no paid rankings
Home / Blog / PHP-FPM: tuning workers without turning the server into a gamble
Guide

PHP-FPM: tuning workers without turning the server into a gamble

Too few PHP-FPM workers and requests queue; too many and RAM collapses. Here is how to calculate pm.max_children from real memory use, not a magic rule.

4 min read Updated Apr 17, 2026

An e-commerce site crashes every Monday morning. The team upgrades the VPS plan. Next Monday, same symptom: blank pages, Nginx returns 502 Bad Gateway. The real issue was not CPU — PHP-FPM had exhausted workers and RAM at once. Tuning FPM means balancing response capacity and memory ceiling. Misconfigured, the server becomes a gamble: visitors wait, or the kernel kills processes.

PHP-FPM manages a pool of PHP processes. Each dynamic request consumes a worker. If all 20 workers are busy, request 21 waits in queue — TTFB spikes. If you launch 200 on 4 GB RAM, the OOM killer steps in.

Read current state before changing anything

Before any forum copy-paste pm.max_children = 50:


# FPM processes and RAM (example www pool)

ps --no-headers -o rss,cmd -C php-fpm8.2 | awk '{sum+=$1} END {print sum/1024 " MB total"}'

Also check:

  • listen.queue in php-fpm status — waiting requests.
  • 502/504 correlated with peaks in Nginx logs.
  • slowlog — scripts holding workers too long.
SignalInterpretation
Queue > 0 regularlyNot enough workers or scripts too slow
RAM swap in useToo many workers or PHP memory leak
idle workers = max alwaysUndersized pool
idle workers = 0, RAM OKSlow scripts, not necessarily small pool

Calculate pm.max_children without magic formulas

Base formula:

max_children ≈ (RAM allocated to PHP pool) / (average RAM per worker under load)

Measure per-worker RAM with realistic traffic (not an empty homepage). Heavy WordPress often runs 60–120 MB per process. Laravel or Magento go higher.

On an 8 GB VPS where PHP can use 4 GB:

  • Average worker: 100 MB → theoretical max 40.
  • Keep 20–30% margin for OS, MySQL, Redis → aim for 28–32, not 40.

pm modes:

ModeBehaviourUse case
dynamicSpawn between min and max by loadVariable sites, good compromise
staticAlways max active workersStable load, minimal latency
ondemandSpawn on demand, idle timeoutTight RAM, accept cold start

slowlog, request_terminate_timeout and common mistakes

request_slowlog_timeout (e.g. 5 s) + slowlog = scripts monopolising workers. Fix code before adding processes.

request_terminate_timeout kills runaway scripts — useful, but can truncate legitimate imports if set too low.

Classic errors:

  1. Copying a production pool to shared hosting — different limits, suspended account.
  2. Ignoring MySQL — 50 workers × slow queries = 50 saturated DB connections.
  3. OPcache disabled or undersized — each worker reloads bytecode, RAM swells (see OPcache).
  4. High max_children + no page cache — WordPress rebuilds everything each hit.

The peak: more workers hide slow application code

This is what "unlimited" offers gloss over: unlimited visitors does not mean unlimited PHP processes.

Decide and move forward without blind spots

  1. Measure RAM/worker and queue length under real load.
  2. Calculate max_children with margin; choose dynamic or static.
  3. Enable slowlog, fix listed scripts.
  4. Retest load and TTFB; compare hosting only if the pool is healthy.

For upstream diagnosis, read High TTFB. To filter VPS with full pool access, browse the directory or comparator.

Frequently asked questions

How do I calculate pm.max_children?

RAM available to PHP divided by average worker use under load, with 20–30% margin.

dynamic, ondemand or static — which to choose?

dynamic for variable traffic; static for stable load; ondemand if RAM is very tight and you accept startup latency.

What if slowlog fills the disk?

Realistic threshold, fix scripts, not just log rotation.

Can the host block my FPM changes?

Yes on shared hosting; on VPS you control the pool — check contractual limits.


Before raising workers, ask: how many MB per request and seconds per script? If you do not know, FPM tuning is gambling — not operations.

Compare European hosts

Filter by compliance, location and use case — then open the sheets to verify the real scope.

Browse the directory
Blog

Related reading

All articles →