Related posts
- XenForo on PHP 8.1 to 8.6: the same build six times
Six PHP series compiled with the same clang recipe and the same extensions, one XenForo forum with 100,000 posts, plain nginx, PHP-FPM and MariaDB. PHP 8.5 and 8.6 serve uncached pages 8-11 % faster than 8.1. 8.2, 8.3 and 8.4 tie, and 8.6 adds nothing over 8.5 yet.
- Compiling Angie too, and the hardening my compiled PHP was missing
Angie compiled from source served cached pages 4-6 % faster; zlib-ng cut its gzip cost by a fifth. PGO, AutoFDO and a static glibc were measured; and the from-source php-fpm got back the stack protector and RELRO that upstream clang leaves off.
- Who compresses a logged-in XenForo page? 12 % of PHP, one fastcgi_param, and a clock that lied
Profiling the member pages of a XenForo forum showed zlib eating 12 % of PHP-FPM CPU: XenForo gzips its own pages at level 9 inside the worker. Moving that to Angie gave +5 % on the forum index and +9 % on thread pages. Along the way, a CPU turbo budget faked a 27 % speed-up, and three other ideas did not survive measurement.
The 1.22.5 cycle of my setup script had one rule: an option that is at least 2 % faster on some XenForo tier, and slower on none, becomes the default. An opt-in that turned out no faster gets deleted, code and all. Every candidate was measured alone first. This post measures the release as a whole.
How I measured#
One box, the Xeon E-2236 (6 cores, 12 threads, 62 GB, NVMe RAID0) with Ubuntu 26.04 and its 7.0 kernel, the clock pinned at 3.6 GHz. The same XenForo forum, the same data, the same member account.
For each run, I applied one release the way a server gets it: two
--optimizeruns under background load (build, then the BOLT profile), then a reboot, because the kernel command line is part of the release. After 60 idle seconds,wrkran five rounds of five tiers:I alternated the releases: 1.22.4 three times and 1.22.5 twice, so a drift in the box would show up as disagreement between runs of the same release. It didn’t. Each tier’s number below is the mean of the runs’ medians.
The result#
The 1.22.4 runs agreed within 2 % on every PHP tier, and so did the 1.22.5 runs, so these gaps are not noise. Tail latency fell with them:
And memory, summed over every process while
wrkran:One detail in the raw rows: the first cached round of every 1.22.4 run scored zero. Right after the reboot it met the page cache still being filled, and the harness rejects a round whose cache status is not a hit. With that zero counted, each median is the second-lowest good round, at most 0.5 % below the median of the four good rounds. So the cached gain is overstated by at most half a percent.
Where the gain comes from#
The release changed five things at once:
mitigations=offenable_file_override=1Two of my 1.22.5 runs had every change but one, by accident (more on that below): PHP kept its 1.22.4 build with glibc’s malloc. That splits off mimalloc cleanly:
Inside the first column, my earlier one-at-a-time runs put dynamic Brotli level 1 at about +4.5 % on the PHP tiers and AWS-LC at a few percent on the cached tier. The rest is the kernel. In round numbers:
mitigations=off: about +26-29 % on cached pages and +8-13 % on PHP pages. A cached hit is mostly system calls, and every one paid for the page-table switch and the buffer clearing.enable_file_override: it earned its place earlier in the cycle, at +3.9 % on member home next to two baselines. In the later sweep it was inside the noise, so most of the 1.22.5 gain comes from the other four.What each one costs#
mitigations=offremoves the kernel’s protection between local processes. My servers are single-tenant, run only my own code and accept SSH keys only, so a hostile local process is already a lost server. On a shared host, keep the mitigations on.Brotli level 1 reverses the compression post, which measured the same speed gain and kept level 4 for its cost: 40 % more bytes on a member thread page (23.9 KB instead of 17.1 KB). This time I measured the guest home page, where the cost is 16 % (11.1 KB instead of 9.5 KB), so it depends on the page.
That post already said an origin whose only client is Cloudflare can take level 1, and every one of my servers is such an origin. The extra bytes travel from the origin to Cloudflare, whose network is not the bottleneck. A server that answers visitors directly pays them on every page.
SETUP_BROTLI_LEVEL=4restores the old level. Levels 2 and 3 fell between 1 and 4 on the PHP tiers.enable_file_overrideanswersfile_exists()and similar calls for cached scripts from OPcache, so a deleted PHP file can look present until OPcache revalidates it.AWS-LC is a reversal of the TLS library post, where OpenSSL stayed the default because the others take features away. The first of those features was kTLS, and kTLS is now gone from the script (see below), so that reason no longer applies. What remains:
ssl_conf_commanddoesn’t exist on AWS-LC, and my config doesn’t use it.PHP stays on OpenSSL, since its OpenSSL extension supports neither alternative.
Session resumption is half there. I wrote that AWS-LC has no shared session cache, and that was too strong. With session tickets off, TLS 1.2 sessions resume from nginx’s shared cache (five of five reconnects). TLS 1.3 sessions do not: AWS-LC resumes them only through tickets, while OpenSSL resumed them from the cache.
So a TLS 1.3 client that reconnects straight to the origin pays a full handshake. With an ECDSA certificate, AWS-LC’s full handshake costs about half the CPU of OpenSSL’s. With the RSA-2048 certificates the script makes for Cloudflare’s Full mode, it costs about 20 % less. Behind Cloudflare the edge keeps its origin connections open anyway.
mimalloc has no cost I could find. PHP’s own memory manager still serves request memory; mimalloc only replaces malloc underneath it.
What got deleted#
These were opt-ins that measured no faster, so their code is gone. A config that still names one gets a warning and the default; nothing fails.
TLS_LIB=openssl: slower than AWS-LC on cached pages.TLS_LIB=boringssl: below AWS-LC, with no OCSP stapling either. With both gone, nginx no longer builds OpenSSL at all.PHP_BUILD_MALLOC=glibcandjemalloc: below mimalloc on every tier.mimalloc and jemalloc for nginx: within the noise of glibc’s malloc.
BOLT_NOLBR: a BOLT profile from plain cycle samples, for CPUs without branch records. It was 1-3 % slower than no BOLT at all.kTLS: 12-36 % slower on the cached XenForo page, on both the Xeon and an AMD EPYC, and no faster on PHP pages. This reverses part of the kTLS post. That post measured 40-44 % less nginx CPU on large files and kept
KTLS=1for servers that mainly send them.That saving was real. But my servers send forum pages through Cloudflare, not downloads, and AWS-LC has no kTLS anyway. A large-file server that terminates its own TLS would be better served by a different build than this script’s.
The bug the benchmark found#
My first two 1.22.5 runs were only 13-18 % faster on PHP pages, and PHP-FPM memory didn’t move at all. The
--optimizelog explained it: the PHP build had failed, withlibxml/parser.hnot found. The safety net worked as designed. It stopped before switching anything, PHP kept running on its 1.22.4 build, and the run exited with an error. But the same thing would have happened on every server that updated, on every run.The cause was in 1.22.5 itself. The script caches the static libraries PHP links against, keyed by CPU, compiler and versions. 1.22.5 changed how the key is computed, so the cache migration renames an existing cache to its new key instead of compiling every library again. The rename was the bug: the libraries’ pkg-config and libtool files still named the old directory, so the compiler looked for headers in a directory that no longer existed.
Every unit test passed, because the fake cache in the test had no pkg-config files. Now the migration rewrites the old name in every file of the cache. Both names are
deps-plus 16 hex digits, so even binaries keep their length. If any reference survives, it drops the cache and builds every library. The test now includes a pkg-config file and a binary.I then recreated a 1.22.4 cache on the box and ran 1.22.5 twice more. Both built PHP on mimalloc, and those two runs are the 1.22.5 numbers above. The rule I take from this: a release benchmark has to install the release the way a real update does, from the previous version’s state. A clean install would have passed.
The raw rows, the per-option sweeps and the harness are in the setup script’s repository, in
tests/stress-site/AUDIT-20261127-1.22.5.md.