Maximizing WordPress Performance with Apache MPM Event, PHP-FPM, and KeepAlive

If you’re hosting hundreds or thousands of WordPress sites on a single high-end server, connection handling and efficient resource management become critical. Modern Apache configurations using MPM Event and PHP-FPM allow servers to handle massive concurrency while keeping CPU and memory usage low.

In this post, we’ll explain how KeepAlive, MPM Event, and PHP-FPM work together and how to tune your server for optimal WordPress performance.

1️⃣ Understanding KeepAlive Connections

KeepAlive allows a client to reuse the same TCP connection for multiple requests instead of opening a new connection for each request. This reduces:

  • TCP handshake overhead
  • SSL/TLS handshake CPU usage
  • Network round-trip latency

In a modern Apache setup with MPM Event, idle KeepAlive connections are monitored asynchronously by the event thread, so they do not block worker threads. This is a huge improvement over older Prefork or Worker MPM setups, where idle connections would consume worker threads and reduce concurrency.

2️⃣ Worker Threads and PHP-FPM

When a client request arrives:

  1. An Apache worker thread handles the request initially.
  2. If the request is dynamic (PHP), it is forwarded to a PHP-FPM worker for execution.
  3. After passing the request to PHP-FPM, the Apache worker thread is released immediately, ready to handle another request.

This separation ensures that worker threads are not tied up during long PHP executions, allowing high concurrency even under heavy WordPress traffic.

3️⃣ Memory and CPU Usage of Idle KeepAlive Connections

Even thousands of idle connections consume surprisingly little resources. Here’s an estimate:

Idle connections Approx. RAM usage
10,000 ~500 MB
50,000 ~2.5 GB
100,000 ~5 GB
200,000 ~10 GB

CPU usage is negligible for idle connections because the event thread monitors sockets asynchronously. Each connection uses roughly 1 file descriptor and ~50 KB of kernel memory.

4️⃣ Why This Matters for WordPress Hosting

WordPress pages typically make 10–20 requests per page (HTML, CSS, JS, images).

Without KeepAlive:

  • Every request requires a new TCP/SSL handshake.
  • CPU and latency increase significantly.

With KeepAlive + MPM Event:

  • Idle connections don’t block workers.
  • PHP-FPM handles dynamic requests independently.
  • Thousands of persistent connections can coexist safely.
  • Overall server efficiency and page load speed improve dramatically.

5️⃣ Recommended Apache + PHP-FPM Tuning

For high-concurrency WordPress hosting:

<IfModule mpm_event_module>
    StartServers            8
    MinSpareThreads         50
    MaxSpareThreads         150
    ThreadLimit             128
    ThreadsPerChild         50
    MaxRequestWorkers       1600
    MaxConnectionsPerChild  20000
    ServerLimit             32
    ListenBacklog           1024
    KeepAlive               On
    KeepAliveTimeout        2
    MaxKeepAliveRequests    1000
</IfModule>

Other recommendations:

  • PHP-FPM pool sizing: adjust pm.max_children according to memory and expected dynamic load.
  • File descriptors: increase ulimit -n and fs.file-max for handling large numbers of connections.
  • KeepAliveTimeout: 2–5 seconds — long enough for multiple requests, short enough to free OS resources.

6️⃣ Full Request Flow Diagram

+-----------------+     (1) TCP connection
|     Client      |--------------------+
+-----------------+                    |
                                       v
                           +----------------------+
                           |   Apache Event Thread |
                           +----------------------+
                                       |
                                       | (2) Incoming request detected
                                       v
                           +----------------------+
                           |  Apache Worker Thread |
                           +----------------------+
                                       |
                                       | (3) Dynamic request (PHP)
                                       v
                           +----------------------+
                           |     PHP-FPM Pool     |
                           +----------------------+
                                       |
                                       | (4) PHP response
                                       v
                           +----------------------+
                           |  Apache Worker Thread |
                           +----------------------+
                                       |
                                       | (5) KeepAlive connection maintained
                                       v
+-----------------+     (6) Subsequent requests reuse same TCP connection
|     Client      |<--------------------+
+-----------------+

Conclusion

Using MPM Event + PHP-FPM + KeepAlive, your WordPress server can safely handle tens of thousands of concurrent connections:

  • Idle connections consume minimal RAM (~50 KB each) and negligible CPU.
  • Workers are freed immediately for new requests.
  • CPU and memory are used efficiently, and SSL/TCP overhead is reduced.

This setup allows high-end servers to serve massive traffic without wasting resources or increasing latency, making it ideal for WordPress hosting at scale.

One thought on “Maximizing WordPress Performance with Apache MPM Event, PHP-FPM, and KeepAlive

Leave a Reply to A WordPress Commenter Cancel reply

Your email address will not be published. Required fields are marked *