Skip to content
Back to Blog
Performance10 min read

PHP-FPM Configuration for WordPress: Memory, Pool Modes & Tuning

Learn how to configure PHP-FPM for WordPress on your VPS by choosing the right process manager mode, calculating max_children based on available RAM, and monitoring pool saturation to prevent performance bottlenecks.

Written by Abdul AbrorTechnical Hosting Support Engineer
PHP-FPM Configuration for WordPress: Memory, Pool Modes & Tuning
On this page

PHP-FPM (FastCGI Process Manager) is the engine behind most WordPress sites running on VPS servers. While the default configuration works for light traffic, a tuned PHP-FPM setup prevents memory exhaustion, reduces response times, and keeps your site stable under load. This guide walks through the three key decisions: choosing a process manager mode, calculating the right number of child processes based on available RAM, and monitoring pool saturation to catch bottlenecks before users do.

Why PHP-FPM Configuration Matters for WordPress

WordPress executes PHP code for every page load—querying the database, rendering templates, processing plugins. PHP-FPM manages a pool of worker processes that handle these requests. Misconfigured pools lead to predictable problems:

  • Too few workers: requests queue up, users see slow page loads or gateway timeouts
  • Too many workers: the server runs out of RAM, triggers OOM kills, or swaps to disk
  • Wrong pm mode: workers sit idle wasting memory, or spawn too slowly under traffic spikes

Unlike Apache with mod_php where every web server process includes PHP, PHP-FPM separates concerns. Nginx or Apache passes requests to a dedicated pool of PHP workers via FastCGI. This means you can tune PHP memory limits independently from your web server, and scale workers based on actual PHP workload rather than static file requests.

Understanding PHP-FPM Process Manager Modes

PHP-FPM offers three process manager modes in the pool configuration file, typically found at /etc/php-fpm.d/www.conf or /etc/php/8.x/fpm/pool.d/www.conf depending on your distribution.

pm = dynamic

The dynamic mode is the default and most flexible choice for WordPress hosting. It maintains a core set of worker processes and scales up or down based on demand.

Key directives:

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
  • pm.max_children: absolute ceiling of worker processes
  • pm.start_servers: how many workers spawn when PHP-FPM starts
  • pm.min_spare_servers: minimum idle workers kept ready
  • pm.max_spare_servers: maximum idle workers before PHP-FPM kills excess ones

Dynamic mode adapts to traffic patterns. During quiet periods, excess workers terminate to free memory. When traffic increases, new workers spawn up to max_children. This balance makes it ideal for WordPress sites with variable traffic—morning surges, content releases, or social media spikes.

pm = static

Static mode maintains a fixed number of workers at all times:

pm = static
pm.max_children = 20

Every worker stays resident in memory regardless of load. This eliminates the overhead of spawning and killing processes, giving predictable performance. Use static mode when:

  • Traffic is consistently high throughout the day
  • You need guaranteed capacity for sustained load
  • Memory is dedicated to PHP (not shared with database or other services)

The tradeoff is wasted memory during low-traffic periods. If your site handles ten requests per hour overnight but keeps twenty workers alive, that's RAM sitting idle. For most WordPress VPS deployments with variable traffic, dynamic mode is more efficient.

pm = ondemand

Ondemand mode spawns workers only when requests arrive and terminates them after a timeout:

pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 10s

Workers exist only while actively processing requests or waiting during the idle timeout. This minimizes memory footprint, making it attractive for:

  • Shared VPS environments hosting multiple sites
  • Development or staging servers with infrequent access
  • Very low traffic sites where occasional spawn latency is acceptable

The downside is cold-start latency. Each worker spawn adds overhead to the first request it handles. For production WordPress sites expecting regular traffic, the cost of constant spawning/termination outweighs the memory savings. Dynamic mode keeps a minimum set of ready workers without the memory commitment of static mode.

Calculating pm.max_children from Available RAM

The most critical PHP-FPM setting is pm.max_children—it caps how many PHP workers can run simultaneously. Set it too high and your server will exhaust RAM. Set it too low and requests will queue, causing slowdowns or timeouts.

Step 1: Determine Available RAM for PHP

Start by checking total memory and accounting for system overhead:

free -h

A typical breakdown on a 4GB VPS:

  • Total RAM: 4GB
  • Operating system + base services: 500MB
  • MySQL/MariaDB: 800MB (adjust based on your buffer pool settings)
  • Nginx or Apache: 100MB (minimal compared to PHP)
  • Redis/Memcached (if used): 256MB
  • Reserved for bursts and filesystem cache: 512MB
  • Available for PHP-FPM: approximately 2GB

This is conservative. Monitor actual usage with htop or vmstat during normal traffic to refine your estimate.

Step 2: Measure PHP Worker Memory

Each PHP-FPM worker consumes memory based on WordPress core, active plugins, and the memory_limit directive in php.ini. To measure real-world usage:

ps aux --sort=-%mem | grep php-fpm | head -n 10

Look at the RSS (resident set size) column. On a typical WordPress site with moderate plugin usage, workers range from 30MB to 80MB. Heavily customized sites with WooCommerce, page builders, or complex themes can reach 100-150MB per worker.

For a more precise average:

ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1; count++ } END { print sum/count/1024 " MB" }'

This calculates the mean memory usage across all running workers. Test during peak traffic or simulate load with a tool like ab (ApacheBench) to capture realistic conditions.

Step 3: Calculate max_children

Use this formula:

pm.max_children = Available RAM for PHP / Average worker memory

Example with 2GB available and 60MB per worker:

max_children = 2000 MB / 60 MB ≈ 33

Round down to leave headroom. Setting pm.max_children = 30 provides a safety margin for memory spikes when WordPress processes complex requests or plugins perform heavy operations.

Adjusting Other Dynamic Mode Settings

Once you have max_children, configure the related directives for dynamic mode:

  • pm.start_servers: typically 20-25% of max_children (e.g., 8 for max_children=30)
  • pm.min_spare_servers: same as start_servers or slightly lower
  • pm.max_spare_servers: 30-50% of max_children (e.g., 12 for max_children=30)

These ensure PHP-FPM keeps enough idle workers to handle traffic bursts without spawning delays, while still terminating excess workers during quiet periods.

Configuring the PHP-FPM Pool

Locate your pool configuration file. On CentOS/RHEL/AlmaLinux:

/etc/php-fpm.d/www.conf

On Ubuntu/Debian:

/etc/php/8.2/fpm/pool.d/www.conf

Adjust the version number in the path to match your installed PHP version.

Edit the file and update the pm directives:

[www]
user = nginx
group = nginx
listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

pm = dynamic
pm.max_children = 30
pm.start_servers = 8
pm.min_spare_servers = 8
pm.max_spare_servers = 12
pm.max_requests = 500

The pm.max_requests directive terminates workers after handling a certain number of requests, preventing memory leaks in poorly coded plugins from accumulating. A value between 500 and 1000 is standard.

After editing, validate the configuration:

php-fpm -t

If the syntax is valid, restart PHP-FPM:

systemctl restart php-fpm

Check that workers are running:

systemctl status php-fpm
ps aux | grep php-fpm | grep -v grep

You should see the master process plus pm.start_servers workers.

Monitoring Pool Saturation

Even with correct calculations, traffic patterns change. Monitoring tells you when you've hit limits before users experience slowdowns.

Enable PHP-FPM Status Page

PHP-FPM includes a built-in status page similar to Apache's mod_status. Enable it in your pool config:

pm.status_path = /fpm-status

Configure Nginx to expose it on a restricted path:

location ~ ^/(fpm-status|fpm-ping)$ {
    access_log off;
    allow 127.0.0.1;
    deny all;
    include fastcgi_params;
    fastcgi_pass unix:/run/php-fpm/www.sock;
}

This allows local access only. Query the status:

curl http://localhost/fpm-status

Key metrics in the output:

  • accepted conn: total requests handled since start
  • active processes: currently processing requests
  • idle processes: workers waiting for requests
  • total processes: active + idle
  • max active processes: peak concurrent workers reached
  • listen queue: requests waiting for an available worker
  • max listen queue: highest queue depth seen

Watch for Queue Growth

The listen queue and max listen queue metrics are critical. If max listen queue is above zero, requests have been delayed waiting for free workers. This indicates pm.max_children is too low for your traffic.

Monitor in real-time:

watch -n 2 'curl -s http://localhost/fpm-status?full'

The ?full parameter adds per-worker details showing what each process is doing.

Interpreting Slow Logs

Enable slow log tracking to identify which scripts or plugins cause bottlenecks:

slowlog = /var/log/php-fpm/www-slow.log
request_slowlog_timeout = 5s

Any request taking longer than 5 seconds generates a log entry with a backtrace. Review the log periodically:

tail -f /var/log/php-fpm/www-slow.log

Common culprits in WordPress:

  • Unoptimized database queries in custom themes
  • HTTP requests to external APIs without timeouts
  • Image processing in media upload handlers
  • Plugin conflicts causing infinite loops

This data guides optimization efforts—caching queries, deferring external calls, or replacing problematic plugins.

Systemd Integration for Alerts

If you run systemd-based monitoring, configure PHP-FPM to restart automatically on failure:

systemctl edit php-fpm

Add:

[Service]
Restart=on-failure
RestartSec=5s

This prevents extended downtime if PHP-FPM crashes due to memory issues or segfaults.

Tuning Memory Limits in php.ini

The PHP-FPM worker memory is constrained by memory_limit in php.ini. WordPress recommends at least 64MB, but modern sites with plugins often need 128MB or 256MB.

Locate your php.ini:

php --ini | grep "Loaded Configuration File"

Edit the directive:

memory_limit = 128M

This applies per worker. If you set memory_limit = 256M and pm.max_children = 30, the theoretical maximum is 7.5GB—more than most VPS plans offer. Keep memory_limit reasonable and tune max_children accordingly.

After changing php.ini, restart PHP-FPM to apply.

Optimizing for WooCommerce and Heavy Plugins

WooCommerce and page builders increase per-worker memory and execution time. Adjust:

  • Raise memory_limit to 256MB if cart or checkout pages trigger memory exhausted errors
  • Increase max_execution_time to 300 seconds for product import scripts
  • Lower pm.max_children to account for higher memory per worker

Consider object caching with Redis or Memcached to reduce database load, freeing up workers faster:

yum install redis php-redis
systemctl enable --now redis

Install a WordPress object cache plugin to connect Redis. This dramatically reduces the time each worker spends waiting on database queries.

Conclusion

Tuning PHP-FPM transforms WordPress performance on a VPS from unpredictable to reliable. Start by choosing dynamic mode for flexibility, calculate pm.max_children from available RAM and measured worker memory, and monitor the status page to catch saturation before it affects users. Review these settings whenever you add plugins, upgrade WordPress, or see traffic growth. Properly configured PHP-FPM prevents the two most common VPS issues—memory exhaustion and request queueing—keeping your site fast under load.

FAQ

How do I know if I need to increase pm.max_children?

Check the PHP-FPM status page. If listen queue or max listen queue is consistently above zero during traffic peaks, requests are waiting for free workers. Increase max_children if you have available RAM.

Should I use static mode for a busy site?

Static mode eliminates process spawn overhead and guarantees capacity, but wastes memory during off-peak hours. Use it if traffic is steady 24/7 and you can dedicate RAM exclusively to PHP. Otherwise, dynamic mode is more efficient.

What happens if I set max_children too high?

The server will spawn workers until it exhausts RAM, triggering the OOM killer. This crashes PHP-FPM or other services like MySQL, causing site downtime. Always calculate max_children based on available memory.

Can I have multiple PHP-FPM pools for different sites?

Yes. Create separate pool config files in /etc/php-fpm.d/ for each site, each with its own socket, user, and tuning. This isolates resource usage and allows per-site memory_limit and max_children settings.

How often should I monitor PHP-FPM status?

Check manually after traffic spikes or plugin updates. For automated monitoring, integrate the status page with tools like Prometheus, Zabbix, or Nagios to alert when queue depth or worker saturation crosses thresholds.