
Your PHP site feel fine all week. Then suddenly newsletter goes out, product get shared, or sale starts, and page that normally load in under second start hanging. To Configure PHP-FPM effectively and improve application performance, you first need to understand what’s happening behind the scenes. You open the PHP-FPM log and find one line repeated over and over:
WARNING: [pool www] server reached pm.max_children setting (5), consider raising it This warning is one of most common PHP-FPM log line on busy server, and in my experience “consider raising it” is start of investigation, not fix. If you configure PHP-FPM by guessing, you can turn slow site into crashing one. Raise worker limit too far and server run out of memory. Leave it too low and request wait in line while CPU sits idle.
In this blog, I will show how request reaches a PHP worker, calculate “pm.max_children” from measured memory, apply changes safely.
TL;DR
- PHP-FPM performance depends on properly configured worker processes, available server memory, CPU capacity, and application workload.
- Choose the right PHP-FPM process manager (dynamic, ondemand, or static) based on your website’s traffic patterns and resource requirements.
- Calculate “pm.max_children” using the measured memory usage (PSS) of busy PHP-FPM workers instead of guessing.
- Monitor PHP-FPM status, request queues, slow logs, CPU, RAM, swap, and database load to identify performance bottlenecks.
- Optimize slow database queries, external API calls, and application code before increasing PHP-FPM worker limits.
- Apply PHP-FPM configuration changes safely by backing up files, testing configurations, and performing graceful reloads.
What PHP-FPM does and where to look for bottlenecks
Before you change single setting, you want clear picture of where request spend its time.
How request travel from Apache to PHP worker: Apache use PHP-FPM, it doesn’t run PHP itself. Apache serve static files directly, and when request hits a “.php” file, “mod_proxy_fcgi” module pass it over FastCGI protocol to PHP-FPM, usually through Unix socket such as “/run/php/php8.3-fpm.sock”. On Ubuntu, that handoff is set in “/etc/apache2/conf-available/php8.3-fpm.conf” with line like:
SetHandler "<code>proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost</code>" This is different from the older “mod_php” setup, where PHP run inside every Apache process. PHP-FPM keep PHP in its own pool of worker, which lets Apache use the lighter “event” MPM and lets you size PHP separately.
PHP-FPM manage one or more pools. Each pool is group of worker process, and each worker handle exactly one request at a time.

So when people say “PHP is slow,” request might be slow inside PHP, or it might be sitting in line waiting for free worker. Those are two very different problems.
Queued requests vs. slow PHP execution
From browser, three different problem look almost identical, page just take long time.
| What’s happening | What browser sees | What actually help |
| Pool saturated, request queuing | Slow first byte, get worse with traffic | More worker if RAM and CPU allow, or faster request |
| Slow database queries | Slow first byte, even at low traffic | Query and index fix, object cache |
| Slow external API call | Random slow page, worker stuck waiting | Timeouts, caching, moving work to queue |
Here’s trap that catch lot of people: Slow database query hold worker for full length of query. With enough traffic, those stuck worker fill pool, and then you see “max_children” warning. Raising limit in that situation only add more worker waiting on same overload database.
What to check before editing PHP-FPM configuration
Find active PHP-FPM service, pool file, and socket
Server often have more than one PHP version installed, and version your shell report with “php -v” isn’t necessarily one Apache uses. On Apache there’s extra thing, PHP might not be running through PHP-FPM at all. I always start from Apache and work backwards:
# Is PHP running through PHP-FPM or the old mod_php module?
sudo apache2ctl -M | grep -E "php|proxy_fcgi|mpm"
# Which PHP-FPM socket does Apache send .php requests to?
sudo grep -R "proxy:unix" /etc/apache2/conf-enabled/ /etc/apache2/sites-enabled/
# Which PHP-FPM services are running?
systemctl list-units --type=service | grep fpm
# Which pool listens on that socket?
sudo grep -R "^listen =" /etc/php/*/fpm/pool.dOn Ubuntu 24.04 default branch is PHP 8.3, and on Ubuntu 26.04 it’s PHP 8.5, so expect paths like “/etc/php/8.3/fpm/pool.d/www.conf” or “/etc/php/8.5/fpm/pool.d/www.conf”.
PHPV=8.3 # change to the version your Apache SetHandler points toIn first command’s output, you want to see “proxy_fcgi_module” and “mpm_event_module”. If you see “php8.3_module” instead, PHP runs inside Apache through “mod_php”, and nothing in this guide’s pool setting will have any effect.
To switch to PHP-FPM (with the matching php8.3-fpm package installed):
sudo a2dismod php8.3 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo apache2ctl configtest && sudo systemctl restart apache2Changing MPM needs full Apache restart, not reload, so do it in quiet period and test your site right after.
Common mistake: editing 8.1 pool file while site runs on 8.3. The edit “does nothing,” and people conclude PHP-FPM tuning doesn’t work.
Capture baseline under representative traffic
I don’t tune anything until I can answer “compared to what?” Before any change, I write down these numbers during normal busy period:
- Response latency: median and p95 time to first byte
- Request rate and error rate: especially 503s and 504s in “
/var/log/apache2/error.log” - CPU, RAM, and swap: from “htop”, “
vmstat 5”, or monitoring panel - Database load: slow query log, connection count, CPU on database server
A quick way to snapshot memory and swap:
free -m
vmstat 5 6If swap usage is climbing during peaks, that’s first thing to note. PHP server that’s swapping will get slower when you add workers, not faster.
The status page is single most useful PHP-FPM diagnostic, and it’s off by default. In your pool file, uncomment or add:
pm.status_path = /fpm-statusI prefer to read it without exposing it to web at all, using “cgi-fcgi” tool to talk to socket directly:
sudo apt install libfcgi-bin
sudo systemctl reload php$PHPV-fpm
sudo env SCRIPT_NAME=/fpm-status SCRIPT_FILENAME=/fpm-status REQUEST_METHOD=GET \
cgi-fcgi -bind -connect /run/php/php$PHPV-fpm.sockIf you’d rather view it through Apache, add localhost-only location to your virtual host. Default PHP-FPM handler only matches “.php” files, so status path need its own rule:
<LocationMatch "/fpm-status">
Require local
ProxyPass "unix:/run/php/php8.3-fpm.sock|fcgi://localhost/"
</LocationMatch>Then run “sudo apache2ctl configtest && sudo systemctl reload apache2” and check it with “curl http://localhost/fpm-status” from server. Never leave it public, because it reveal traffic and process detail about your server.
Here’s an example of the output, with fields I actually care about:
pool: www<br>
process manager: dynamic
start since: 3612
accepted conn: 48215
listen queue: 0 <- requests waiting right now
max listen queue: 37 <- worst queue since start
listen queue len: 511 <- maximum queue size
idle processes: 2
active processes: 8
total processes: 10
max active processes: 10
max children reached: 14 <- times the pool hit its ceiling
slow requests: 6 <- requests that crossed the slowlog
timeoutThe PHP-FPM status page reference explain which field show activity right now and which summarize activity since pool started.
Counters like “max children reached” and “slow requests” are cumulative since last restart or reload. A value of 14 could be from one spike last Tuesday. So you can sample it twice:
for i in 1 2; do<br>
sudo env SCRIPT_NAME=/fpm-status SCRIPT_FILENAME=/fpm-status REQUEST_METHOD=GET \
cgi-fcgi -bind -connect /run/php/php$PHPV-fpm.sock \
| grep -E "listen queue:|max children reached|slow requests|active processes:"
[ $i -eq 1 ] && sleep 60
doneIf “max children reached” is cumulative counter of how many time PHP-FPM reached worker limit when trying to spawn more worker (for “dynamic” and “ondemand” pool). Compare two sample: if counter increase, pool hit its limit during that interval. To check whether pool is saturated right now, look at “listen queue” and “active processes”.
If status check itself stall during traffic spike, you can give status request separate FastCGI listener with pm.status_listen, so check can respond while main pool is busy.
Choose process manager that fits your traffic
The “pm” setting control how PHP-FPM create and remove workers. All three modes respect “pm.max_children” as hard ceiling. They differ in how many worker they keep ready.
Dynamic for site that benefit from ready worker
“dynamic” keep flexible number of worker alive. This is Ubuntu’s default and what use for most production site.
pm.start_servers: workers created when the pool startspm.min_spare_servers: if fewer idle workers exist, PHP-FPM spawns morepm.max_spare_servers: if more idle workers exist, PHP-FPM kills the extras
The upside is sudden burst find worker already waiting. Cost is that idle worker hold memory. If you see “seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers)” in log, your spare settings are too tight for your burst pattern.
ondemand for low-traffic pools
“ondemand” start with zero worker and spawn them only when request arrive. Idle worker are killed after “pm.process_idle_timeout” (10 seconds by default).
I like “ondemand” for staging site, admin panel, and small client site sharing one server, because quiet pool use almost no memory. Trade-off is worker startup delay. The first request after quiet period pay cost of forking process, and with no warm worker ready, burst feels it more.
static for predictable workloads
“static” keep exactly “pm.max_children” worker running at all time. There’s no spawning delay and no churn, so latency is very consistent.
Cost is that you pay full memory bill 24/7, even at 3 a.m. I only use “static” on dedicated server where PHP app is main tenant, traffic is steady, and I have already measured that memory fits.
| Points | Dynamic | Ondemand | Static |
| Best traffic pattern | Variable traffic with regular peak | Low or occasional traffic | Steady, predictable traffic |
| Idle memory | Medium (spare worker stay alive) | Very low (worker exit when idle) | High (all worker always alive) |
| Burst behavior | Good. Spare absorb start of burst | Slower. Worker spawn as request arrive | Best. Full capacity always ready |
| Typical use | Most production site | Staging, small site, many pool on one server | Dedicated app server |
Calculate pm.max_children from measured memory
It’s part that decide whether your server survive next traffic spike.
Measure busy worker under real application load
Two shortcut give misleading number:
- Idle worker memory. Worker that has just started hasn’t loaded your framework, plugin, or data yet, so it look far smaller than it will be under load.
- PHP’s “
memory_limit”. That is maximum single script may use, not what it typically use. Sizing from 256 MB limit usually gives ceiling that’s far too low.
Even common “ps” RSS column overstate real cost, because PHP-FPM worker share memory with master process (code page, OPcache shared memory). RSS count that shared memory in every worker.
Use proportional set size (PSS) to estimate worker memory. Linux kernel’s /proc documentation explain how PSS assign each process share of shared memory and how “smaps_rollup” sums memory across its mapping.
Run this while site is under typical traffic, not at idle:
sudo bash -c '
total=0
count=0
max=0
for pid in $(pgrep -f "^php-fpm: pool www$"); do
pss=$(awk "/^Pss:/ {print \$2; exit}" /proc/$pid/smaps_rollup 2>/dev/null) || continue
[ -n "$pss" ] || continue
total=$((total + pss))
count=$((count + 1))
[ "$pss" -gt "$max" ] && max=$pss
done
if [ "$count" -eq 0 ]; then
echo "No PHP-FPM workers found for pool www."
else
awk -v n="$count" -v s="$total" -v m="$max" \
"BEGIN {printf \"workers: %d avg PSS: %.0f MB max PSS: %.0f MB\n\", n, s/n/1024, m/1024}"
fi
'I take several samples across busy period and consider both average and maximum worker memory usage. Heavy route like report, import, or WooCommerce checkout can use much more memory than cached blog page. Use representative peak workload when estimating worker memory, and leave enough memory headroom for spike.
Adjust for CPU, database capacity, and multiple pools
Memory set upper limit. CPU and database often set lower one.
CPU: On 2 vCPUs, only two workers can actually execute PHP code at same instant. Extra worker help only when request spend time waiting, on database, Redis, or external API. If your request mostly CPU-bound, 25 worker on 2 cores just mean 25 request fighting over 2 core, and every one of them finish later.
Database: Every busy PHP worker can hold database connection. If MariaDB is already bottleneck, more PHP worker send more simultaneous queries to overloaded database, and everything slow down together. Check “max_connections” and database CPU before raising PHP ceiling.
If database connection are already piling up, use guide to troubleshooting MySQL’s “Too many connections” error to check what is holding connection open before adding PHP worker.
Multiple pools: If one server run several site, each with its own pool, pool can peak at same time. The rule to follow:
sum of (pm.max_children × busy-worker PSS) across all pools ≤ PHP-FPM memory budgetOn shared server, give smaller sites “ondemand” with low ceiling, and reserve most of budget for site that actually gets traffic.
Apache’s own limit: With “event” MPM, “MaxRequestWorkers” caps how many request Apache handles at once. Ubuntu’s default in “/etc/apache2/mods-available/mpm_event.conf” is 150, which is comfortably above 25 PHP worker. Static file request and other concurrent request also consume Apache capacity. Make sure “MaxRequestWorkers” is sufficient for your expected traffic and does not become bottleneck before PHP-FPM. The appropriate value depend on your Apache MPM, workload, and server resource.
Configure pool and apply change safely
Build sample dynamic pool configuration
Here is pool configuration based on example of 4 GB, with each value tied back to calculation:
[www]
user = www-data
group = www-data
listen = /run/php/php8.3-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 25 ; 1,796 MB budget ÷ ~70 MB busy PSS, rounded down
pm.start_servers = 6 ; ~25% of max, ready for normal daytime traffic
pm.min_spare_servers = 4 ; keeps a few warm workers for small bursts
pm.max_spare_servers = 10 ; trims idle workers to give memory back
pm.max_requests = 500 ; recycle workers to contain slow memory growth
pm.status_path = /fpm-status
slowlog = /var/log/php8.3-fpm-www-slow.log
request_slowlog_timeout = 5sFor “dynamic” pool, set “pm.start_servers” to value that make sense within your configured spare-worker range. Keep “pm.min_spare_servers” and “pm.max_spare_servers” consistent with expected traffic and available memory.
Decide when to use pm.max_requests
“pm.max_requests” tell each worker to exit and be replace after handling that many request. The default of “0” mean worker live forever.
I set it when worker memory creep upward over hour. You can spot that by running PSS measurement in morning and again in evening. Slow leak in extension or plugin is contained when worker are recycled regularly.
Don’t set it too low, though. Every recycle means forking new process and warming it up again. Value like 50 on busy site create constant churn. Something in 300–1,000 range is a sensible starting point, and if memory stays flat over a day, you may not need it at all.
Back up, validate, reload, and roll back
This can be routine every single time, even for one-line change:
PHPV=8.3
POOL=/etc/php/$PHPV/fpm/pool.d/www.conf
# 1. Back up (note: backup name must NOT end in .conf)
sudo cp $POOL $POOL.bak-$(date +%F-%H%M)
# 2. Edit
sudo nano $POOL
# 3. Test configuration
sudo php-fpm$PHPV -tExpected output:
NOTICE: configuration file /etc/php/8.3/fpm/php-fpm.conf test is successfulThat backup naming rule come from mistake worth avoiding. PHP-FPM load every file in “pool.d/” that ends in “.conf”. Backup named “www-old.conf” get loaded as second pool fighting for same socket, and PHP-FPM refuse to start.
If test pass, reload gracefully:
# 4. Graceful reload: workers finish their current request first
sudo systemctl reload php$PHPV-fpm
# 5. Post-reload checks
systemctl status php$PHPV-fpm --no-pager
sudo journalctl -u php$PHPV-fpm --since "5 minutes ago" --no-pagerThen load few real page, re-read status page, and confirm “process manager” and worker count match new setting. Rollback is same process in reverse:
sudo cp $POOL.bak-2026-11-29-1130 $POOL # use your backup's actual name
sudo php-fpm$PHPV -t && sudo systemctl reload php$PHPV-fpmDiagnose slow request before tuning timeout or queue
Enable and read PHP-FPM slow log
If status page show “slow requests” climbing, slow log tell you why. With “request_slowlog_timeout = 5s” set, PHP-FPM writes backtrace for any request still running after 5 seconds:
[29-Nov-2026 11:42:07] [pool www] pid 21844
script_filename = /var/www/example.com/index.php
[0x00007f...] curl_exec() /var/www/example.com/wp-content/plugins/some-plugin/api.php:88
[0x00007f...] fetch_rates() /var/www/example.com/wp-content/plugins/some-plugin/api.php:41
...Read top line of the trace first. It’s function worker was stuck in when timer fired.
- “
curl_exec()” or “file_get_contents()” on URL: external HTTP call is holding worker - “
mysqli_query()” or “PDOStatement->execute()”: slow database query - “
sleep()”, “usleep()”, or lock functions: code is deliberately waiting
When I find slow external call holding worker, fix is timeout on that call and caching its result, not more worker.
Understand listen.backlog and request timeout
Request wait in few different place, and each has its own limit:
- “listen.backlog” (pool setting): how many connection can wait in socket queue. The default is 511, and kernel’s “
net.core.somaxconn” caps it. Raising it only lets more requests wait. It doesn’t make them faster. - “request_terminate_timeout” (pool setting): PHP-FPM kills worker whose request run longer than this. It’s off by default. Setting something like “
60s” stop runaway script from holding worker forever. - “max_execution_time” (php.ini): PHP’s own script limit. On Linux it count only execution time, not time spent waiting on database or network, so request stuck on slow API can blow past it.
- “ProxyTimeout” (Apache): It control how long Apache wait for I/O with FastCGI backend.
If you leave “ProxyTimeout” unset, Apache use its TimeOut setting, so check active configuration before assuming timeout value.
Five minutes is long time for visitor to stare at blank page, so I usually set shorter limit in virtual host:
ProxyTimeout 60I then keep “request_terminate_timeout” slightly above “ProxyTimeout”. That way Apache answer visitor first, and PHP-FPM clean up stuck worker shortly after.

Fix common symptoms
| Symptom | Evidence to check | Next action |
| Listen queue rising | Status page listen queue > 0 during normal traffic, active = max_children | Check RAM headroom and slow log, then raise pm.max_children within your memory budget |
Repeated max_children warnings | Counter keeps rising between samples | Same as above, but first rule out slow DB or API calls holding workers |
| 503 Service Unavailable | Apache error log: AH02454: FCGI: attempt to connect to Unix domain socket ... failed and AH01079: failed to make connection to backend | Check service status, socket path, permissions. If overloaded, check active workers and queued requests |
| 504 Gateway Timeout | Apache error log: AH01075: Error dispatching request with The timeout specified has expired | Find slow request in slow log. Fix cause before raise ProxyTimeout |
| PHP changes have no effect | apache2ctl -M lists php8.3_module | Apache is using mod_php. Switch to PHP-FPM as shown earlier |
| Out-of-memory kills | dmesg or journalctl -k shows Out of memory: Killed process ... php-fpm | Lower pm.max_children, re-measure PSS, consider pm.max_requests |
Decide whether to keep, adjust, or revert change
- Queue gone, latency down, memory stable: keep it, and note new values somewhere your team can find them.
- Queue shrinks but database load rises and latency barely moves: bottleneck has moved to database. Fix queries or add caching, and consider stepping workers back down.
- More workers, but requests got slower: usually CPU contention or swapping. Check “
vmstat” for swap activity and CPU steal, then lower “pm.max_children”. - New OOM kills or swap: revert immediately, then re-measure PSS under load.
Change one thing at time. If you change worker counts, and timeouts together, you won’t know which one helped or hurt.
If you have staging environment, follow this website load testing guide to runsame traffic pattern against both configuration to compare latency and error.
Key takeaways
- Choose right process manager: Use “
dynamic” for most production website, “ondemand” for low-traffic site, and “static” for predictable workload with sufficient memory. - Set “
pm.max_children” carefully: Balance PHP-FPM concurrency with available RAM, CPU core, and database capacity to avoid resource exhaustion. - Monitor PHP-FPM performance: Use PHP-FPM status page and slow log to identify worker saturation, queued request, and long-running PHP script.
- Avoid blindly increasing worker limit: More PHP-FPM worker can increase CPU contention, database load, and memory consumption instead of improving performance.
- Optimize actual bottleneck: Slow database queries, external API call, uncached request, and inefficient code can keep worker occupied.
- Make changes safely: Back up configuration files, validate settings, reload PHP-FPM gracefully, and monitor performance after every change.
Conclusion
Properly configuring PHP-FPM help improve PHP application performance, handle concurrent request, and maintain server stability. By choosing right process manager, calculating “pm.max_children” based on actual memory usage, and monitoring server resource, you can optimize PHP-FPM without overloading your server.
However, increasing worker limit alone won’t fix every performance issue. Optimizing slow database queries, external API calls, and application code is equally important for achieving faster response time, better resource utilization, and reliable performance under traffic spikes.
FAQs
1. What is good starting value for “pm.max_children”?
Take memory left after OS, web server, database, and cache, keep about 10% as headroom, and divide by PSS of busy worker. On 4 GB VPS with roughly 1.8 GB for PHP and 70 MB worker, that’s about 25. Start lower if your request are CPU-heavy or your database is already busy.
2. Is dynamic or ondemand better for WordPress?
For WordPress site with regular traffic, “dynamic” is usually better, because spare worker absorb burst without spawning delay. “ondemand” suit low-traffic WordPress site or many small site on one server, where saving idle memory matter more than first-request delay.
3. Why does PHP-FPM keep reaching pm.max_children?
Either traffic genuinely need more concurrent worker, or each request hold worker too long. Check status page for rising counter and slow log for stuck request. Slow database queries, external API call, and uncached page are most common cause.
4. Can too many PHP-FPM worker make my website slower?
Yes, extra worker compete for limited CPU core, open more database connection, and can push the server into swap. Past certain point, each request waits longer for CPU or the database, so latency rises even though more workers are running.
5. How do I apply PHP-FPM configuration changes without full service restart?
Test config with “sudo php-fpm8.3 -t” (use your version), then run “sudo systemctl reload php8.3-fpm”. A reload replace workers gracefully, letting in-flight request finish, so site stays up during change.
About the author
Meghna Meghwani is a technical writer focused on Linux, Ubuntu, VPS hosting, server management, WordPress, PHP, Node.js, cloud hosting, and DevOps. She creates beginner-friendly tutorials, practical hosting guides, troubleshooting articles, and server security content designed to help developers and businesses manage applications and servers more efficiently.
