Console Login
Home / Blog / Performance Optimization / PHP-FPM vs mod_php: Tuning High-Performance LAMP Stacks in 2011
Performance Optimization 10 views

PHP-FPM vs mod_php: Tuning High-Performance LAMP Stacks in 2011

@

Breaking the Speed Limit: Migrating from mod_php to PHP-FPM

If you are running a high-traffic site on a standard LAMP stack right now, you are likely bleeding RAM. It is the classic November rush—e-commerce stores are gearing up for the holidays, and your Apache error logs are screaming about MaxClients being reached. The server starts swapping. Latency spikes. Your Norwegian customers, accustomed to blazing fast internet, bounce to a competitor.

The culprit is usually the outdated way we handle PHP. For years, mod_php has been the default. It embeds the PHP interpreter inside every single Apache process. This means if Apache is serving a static .jpg, it is still dragging around the memory overhead of a PHP interpreter. It is inefficient, and frankly, it is killing your performance.

The solution is decoupling. Enter PHP-FPM (FastCGI Process Manager).

The Architecture Shift

In a modern 2011 setup, we stop asking Apache to do everything. Instead, we can use Nginx (which uses an asynchronous event-driven architecture) to handle connections and static files, passing only the PHP requests to a dedicated pool of workers: PHP-FPM.

Even if you are stuck with Apache due to .htaccess dependencies, you can still use FastCGI. But the real power comes from the LEMP stack (Linux, Nginx, MySQL, PHP).

War Story: The Magento Memory Leak

Last month, we migrated a Magento 1.5 store hosted in Oslo. They were on a massive dedicated server but crashed daily at 600 concurrent users. top showed Apache processes consuming 80MB each. With mod_php, those processes lived as long as the HTTP keep-alive, holding onto memory they didn't need.

We switched them to Nginx + PHP-FPM. The result? Memory usage dropped by 60%. Page load times went from 1.2s to 350ms.

Configuring the FPM Pool

Installing it is simple on CentOS 6 (via the EPEL repo) or Debian Squeeze. But the magic is in the configuration. The default settings in /etc/php5/fpm/pool.d/www.conf are rarely optimized for production.

Here is the configuration strategy for a CoolVDS node with 4GB RAM:

; /etc/php5/fpm/pool.d/www.conf

; Choose how the process manager controls child processes
pm = dynamic

; The maximum number of child processes to be created
; Calculation: (Total RAM - OS/DB RAM) / Avg Process Size
; Example: (4096MB - 512MB) / 60MB = ~60
pm.max_children = 50

; The number of child processes created on startup
pm.start_servers = 10

; The desired minimum number of idle server processes
pm.min_spare_servers = 5

; The desired maximum number of idle server processes
pm.max_spare_servers = 20

; How many requests each child process should execute before respawning
; profound for fixing memory leaks in 3rd party libraries
pm.max_requests = 500
Pro Tip: Never trust the defaults for pm.max_children. If set too high, FPM will spawn workers until your server swaps to death. Measure your average PHP process size using ps_mem.py or top and calculate the limit strictly.

Don't Forget the APC Accelerator

Tuning FPM is half the battle. PHP is an interpreted language; it compiles code to opcodes on every execution. In 2011, running PHP without an opcode cache is negligence.

APC (Alternative PHP Cache) stores these compiled opcodes in shared memory. This eliminates the compilation step for repeated requests.

To install: pecl install apc

Add to your php.ini:

extension=apc.so
apc.enabled=1
apc.shm_size=128M
apc.ttl=7200
apc.user_ttl=7200

Without APC, your CPU burns cycles recompiling the same WordPress or Drupal core files thousands of times per hour. With APC, that load vanishes.

The Infrastructure Factor

Software tuning only goes so far. The underlying I/O throughput is the final bottleneck, especially for session handling and caching if you aren't using Memcached.

At CoolVDS, we don't oversell our host nodes. We use enterprise-grade RAID-10 SAS storage and true hardware virtualization (KVM/Xen). Why does this matter for PHP-FPM? Because when a worker process writes a session file or a log entry, high I/O wait (iowait) on a crowded budget VPS will block that worker. Blocked workers mean queued requests. Queued requests mean timeouts.

Data privacy is also paramount. Under the Norwegian Personal Data Act (Personopplysningsloven), you are responsible for your customer's data. Hosting on CoolVDS ensures your data resides on secure infrastructure that respects local compliance standards, keeping latency to the Norwegian Internet Exchange (NIX) minimal.

Next Steps

Stop letting Apache manage your memory. It is bad at it.

  1. Install nginx and php5-fpm.
  2. Tune your pm.max_children based on your available RAM.
  3. Enable APC immediately.

If you need a sandbox to test this LEMP stack without risking your production environment, spin up a CoolVDS instance today. You can have a root terminal in under a minute.

/// TAGS

/// RELATED POSTS

Taming Latency: Tuning NGINX as an API Gateway on Linux (2015 Edition)

Is your REST API choking under load? We dive deep into Linux kernel tuning, NGINX upstream keepalive...

Read More →

Stop Letting Apache mod_php Eat Your RAM: The PHP-FPM Performance Guide

Is your server swapping during peak hours? We ditch the bloated Apache mod_php model for the lean, m...

Read More →

Stop Wasting RAM: Migrating from Apache mod_php to Nginx & PHP-FPM on CentOS 6

Is your server swapping out under load? The old LAMP stack architecture is dead. Learn how to implem...

Read More →

Stop Using mod_php: Optimizing PHP Performance with FPM and Nginx

Is your web server struggling under load? Learn why moving from Apache's mod_php to PHP-FPM and Ngin...

Read More →

Stop Watching 'wa' in Top: Why Spinning Disks Are the Bottleneck in 2011

Is your server load spiking despite low CPU usage? The culprit is likely I/O wait. We break down why...

Read More →

Stop Killing Your Disk I/O: migrating PHP Sessions to Redis (2011 Edition)

Is your application hanging on 'waiting for localhost'? File-based session locking is likely the cul...

Read More →
← Back to All Posts