OpenLiteSpeed vs Nginx PHP Isolation

Scrolling system log output during a load stress test
Scrolling system log output during a load stress test (Photo via Unsplash)

Single-site benchmarks lie. Point wrk at a fresh WordPress install on almost any modern stack and you'll pull 18,000 requests per second out of a $20 VPS. That tells you nothing about running a multi-tenant CMS host.

Put 75 WordPress, WooCommerce, and Drupal tenants onto one 16-core, 64 GB Debian box and the failure modes change overnight. Tenant #37 installs a sloppy inventory sync plugin that parks 12 PHP workers on dead upstream sockets. Tenant #14 updates a category archive and kicks off a cache stampede across 400 pages. Suddenly synthetic RPS stops mattering. What matters is blast radius, memory ceilings, cache invalidation accuracy, and how fast you can catch the offender at 3:00 AM.

Over the last few years I've operated production multi-tenant fleets on both OpenLiteSpeed with LSPHP (via LSAPI) and classic Nginx with PHP-FPM, regularly sanity-checking our numbers against the CMS infrastructure comparisons at CMS Connection. OpenLiteSpeed—the open-source cousin of the commercial LiteSpeed Web Server—brings real architectural wins that Nginx lifers dismiss too quickly. It also carries operational warts its fans gloss over. Here is how both stacks hold up once real tenants move in.

Process Isolation: Containing the Noisy Neighbor

Multi-tenant PHP isolation comes down to three walls: UID/GID ownership, worker concurrency caps, and OPcache shared memory separation. Both stacks enforce UID/GID boundaries, yet they structure the process tree quite differently.

With Nginx and PHP-FPM, each tenant gets a pool config under /etc/php/8.3/fpm/pool.d/ bound to a Unix socket with 0660 permissions owned by the tenant user and Nginx's group:

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

pm = ondemand
pm.max_children = 8
pm.process_idle_timeout = 20s
pm.max_requests = 500
request_terminate_timeout = 45s
php_admin_value[open_basedir] = /srv/www/acme:/tmp

Auditing that pool takes five seconds, though a single shared PHP-FPM master carries a catch. Because PHP-FPM allocates OPcache in the master before forking, every pool under that master shares one OPcache SHM segment. Setting opcache.validate_permission=1 and opcache.validate_root=1 stops cross-tenant bytecode execution, or you can run dedicated systemd PHP-FPM masters per tenant. Separate masters pair cleanly with cgroup v2 memory limits, at the cost of extra service-unit boilerplate.

OpenLiteSpeed takes another route with LSAPI and suEXEC. Instead of one host-wide PHP master, OpenLiteSpeed forks a standalone lsphp parent per tenant UID/GID from a vhost external app block:

extprocessor lsphp_acme {
  type                    lsapi
  address                 uds://tmp/lshttpd/lsphp_acme.sock
  maxConns                8
  env                     PHP_LSAPI_CHILDREN=8
  env                     LSAPI_AVOID_FORK=0
  env                     LSAPI_MAX_IDLE=60
  initTimeout             30
  persistConn             1
  autoStart               2
  path                    /usr/local/lsws/lsphp83/bin/lsphp
  instances               1
  extUser                 acme
  extGroup                acme
  runOnStartUp            3
  memSoftLimit            1024M
  memHardLimit            1536M
  procSoftLimit           30
  procHardLimit           40
}

Setting runOnStartUp 3 activates detached mode. Each tenant's lsphp parent survives graceful OpenLiteSpeed reloads and owns a private OPcache segment. One noisy tenant stuffing its cache with bloated page-builder closures never evicts another customer's compiled scripts. On kernel-level containment, though, Nginx plus per-tenant systemd FPM units still wins: OpenLiteSpeed leans on UID/GID permissions, open_basedir, and POSIX rlimits rather than native cgroup v2 CPU and I/O quotas (unless you buy CloudLinux CageFS alongside commercial LiteSpeed).

Memory Predictability Under Tenant Spikes

Private OPcache isn't free. On a 64 GB host carrying 80 tenants, giving each lsphp parent a modest 96 MB OPcache reserves 7.6 GB before a single checkout runs. Detached parents stay warm unless LSAPI_MAX_IDLE reaps them aggressively, and dropping that timer to 15 seconds kills the warm-cache benefit on intermittent traffic.

Worse, OpenLiteSpeed's memSoftLimit and memHardLimit enforce RLIMIT_AS (virtual address space), not physical RSS. Modern PHP extensions, glibc arenas, and ImageMagick routinely reserve hundreds of megabytes of virtual address space while using 60 MB of real RAM. Cap memHardLimit at 512M and ImageMagick or OPcache JIT throws cryptic allocation errors with 30 GB free on the node. Raise it to 2048M and four misbehaving plugins can still starve the host.

PHP-FPM behaves like clean arithmetic. In my notes on PHP-FPM max_children sizing on Linux, measuring steady-state worker RSS and dividing available RAM produces dependable hard ceilings. With pm = ondemand on quiet brochure sites and pm = dynamic on busy stores, idle tenants occupy zero worker RAM. Pairing strict pool caps with cgroup memory high-water marks makes keeping the Linux OOM killer off web nodes far more predictable than tuning virtual address ceilings in LSAPI.

Pack 65 low-traffic CMS sites onto a 32 GB node and PHP-FPM ondemand beats detached LSPHP on RAM density every time. Drop to 15 active WooCommerce stores on that same hardware and per-tenant LSPHP OPcache earns its keep fast.

Tag-Based Cache Invalidation and ESI

If memory math and systemd integration favor Nginx, why deploy OpenLiteSpeed at all? Dynamic CMS caching—specifically tag-based invalidation and Edge Side Includes (ESI).

Nginx full-page caching is wicked fast. As covered in my write-up on Nginx FastCGI cache for heavy PHP, serving anonymous pages from tmpfs drops TTFB below 15 ms and absorbs brutal traffic bursts. The pain starts when an editor updates a product price or publishes a post.

Open-source Nginx ships without native selective cache purging. You either compile ngx_cache_purge, write a helper that hashes MD5 cache keys and unlinks files, or wipe the tenant's entire cache on every edit. Once a shopper adds an item to a WooCommerce cart, standard FastCGI rules bypass the cache completely on the woocommerce_items_in_cart cookie, sending every click straight back to PHP.

OpenLiteSpeed's built-in LSCache module handles both via plain response headers. On render, the CMS plugin tags every entity embedded in the HTML:

X-LiteSpeed-Cache-Control: public,max-age=604800,esi=on
X-LiteSpeed-Tag: B1_P412,B1_T9,B1_T14,B1_F

When product 412 goes out of stock, the plugin replies with X-LiteSpeed-Purge: tag=B1_P412,B1_T9. OpenLiteSpeed evicts only the affected product page, category archive, and front page while leaving the rest of the catalog hot.

ESI pushes that further. The CMS serves a publicly cached product template containing an <esi:include> block for the mini-cart or account badge, cached privately per session cookie for 30 minutes. OpenLiteSpeed assembles the public shell and private block in C before writing to the socket. Nginx's SSI can stitch subrequests, yet it lacks native private-per-cookie caching and tag dependency graphs. OpenLiteSpeed also delivered stable QUIC and HTTP/3 years before Nginx merged experimental support into mainline, and its UDP path still handles lossy mobile links with less fuss.

The .htaccess Parsing Trap

Plenty of operators move from Apache to OpenLiteSpeed expecting drop-in .htaccess support and get burned. OpenLiteSpeed acts nothing like Apache—and differently from commercial LiteSpeed Enterprise.

Apache runs stat() up every directory tree on every request, burning CPU and dentry cache on deep WordPress upload hierarchies. Commercial LiteSpeed caches parsed rules in RAM and watches timestamps for live changes. OpenLiteSpeed reads only RewriteRule and RewriteCond directives (silently ignoring Header, FilesMatch, and php_value), and loads them strictly at startup or graceful reload.

Runtime .htaccess overhead is zero, which is great for latency. The operational snag is workflow drift: a tenant clicks "Save Permalinks" or activates a redirect plugin, the file updates on disk, and nothing changes until OpenLiteSpeed reloads. Many shared hosts bolt on an inotifywait watcher or five-minute cron calling lswsctrl reload. That works until a bad plugin writes 20 times in a loop or injects broken regex, triggering reload storms across every tenant on the box.

Nginx refuses to play the game at all: no .htaccess, period. Every rewrite lives in version-controlled server blocks under /etc/nginx/sites-enabled/. Clients complain on day one, then your on-call rotation enjoys quiet nights for years.

Debugging Tooling at 3:00 AM

When production melts down, Nginx and PHP-FPM are straightforward to dissect:

  • nginx -t catches syntax errors pre-reload, and JSON access logs expose $request_time, $upstream_connect_time, $upstream_header_time, and $upstream_cache_status natively.
  • PHP-FPM's request_slowlog_timeout = 3s dumps exact PHP file paths, line numbers, and stack traces per pool whenever a worker hangs.
  • Hitting a pool socket's /status?full&json endpoint via cgi-fcgi shows active children, listen queue depth, and stalled script durations from the terminal.
  • Battle-tested Prometheus exporters exist for both layers, making per-tenant saturation dashboards trivial.

OpenLiteSpeed is noticeably murkier under pressure. Its indented block syntax in httpd_config.conf and vhconf.conf fights standard Jinja templating and linting, and half the official docs assume you're clicking through the WebAdmin panel on port 7080. LSAPI is a proprietary binary wire protocol, so standard FastCGI CLI tools can't probe an lsphp socket. Per-pool slow stack traces aren't as clean as PHP-FPM's slowlog either; you often end up attaching strace to a wedged lsphp worker or digging through split error.log and stderr.log files.

Live metrics sit in a flat snapshot file at /tmp/lshttpd/.rtreport refreshed every second:

grep -e "^BPS_IN" -e "^REQ_RATE" -e "^EXTAPP" /tmp/lshttpd/.rtreport

It's fast to scrape with a tiny Go or Python collector, and it exposes external app queue depths cleanly, yet maintaining a custom parser just to see if tenant 42 is pegging its workers feels clunky next to PHP-FPM's JSON status socket.

How I Split Workloads Today

After enough 3:00 AM incidents on both stacks, I stopped treating this as dogma and split our clusters by workload:

  • Pick OpenLiteSpeed and LSPHP for WooCommerce, LMS sites, and high-churn editorial CMS tenants where logged-in carts and frequent edits wreck naive full-page caches. Tag purging and ESI routinely halve database CPU on those nodes, and detached suEXEC OPcache isolation is clean once you budget the RAM.
  • Pick Nginx and PHP-FPM when you pack dense tenant counts onto tight RAM, manage everything through Ansible or Terraform, need strict per-tenant cgroup v2 accounting, or want native slowlogs and Prometheus metrics without custom glue.

Neither server fixes slow SQL or bloated plugins. Match the isolation and caching model to your worst tenants, cap every worker pool conservatively, and test your reload pipeline before a WordPress update tests it for you.

Comments

Popular posts from this blog

PHP FPM Max Children Sizing on Linux

Systemd Socket Tuning for High Load

Redis Object Cache Memory Eviction