Related posts
- clang, PHP 8.4 and the missing zlib: the last round of compiled PHP
The final round of the compiled-PHP question: CentminMod's function alignment on its own, a clang build and PHP 8.4, with every module compiled from source. clang is the only build with a repeatable edge (+3 % on XenForo), 8.4 is slower than 8.5, and my earlier source builds were missing zlib.
- Everything on: LTO, PGO and -march=native made PHP 8.5 slower
A follow-up to the four-build PHP test: turn on every CentminMod compiler option, add LTO and two-stage PGO trained on real XenForo traffic, and compile every module from source. The result is 5 to 10 % slower than the distribution package, not faster.
- Is a compiled PHP faster? Four builds, one Xeon, and a JIT that makes the question moot
Sury packages, Ubuntu's archive, and PHP built from source with -O3 -march=native and only the modules XenForo needs. On a PHP-bound forum the difference was inside the noise, and the reason is the tracing JIT.
Guest pages on my forums are a solved problem. They come out of Angie’s FastCGI cache at 125–135k requests per second on the 12-thread test box, and the remaining cost is TLS. The pages that still cost real money are the ones nobody can cache: logged-in members. Every member view runs XenForo end to end, and on this hardware that meant about 260 thread pages per second.
So this cycle had one question: what is left on the logged-in path that the server, not the application, can make cheaper? My provisioning script already does the usual list: OPcache with the tracing JIT, one PHP-FPM worker per CPU thread, persistent database connections, sessions and cache in Valkey, MariaDB’s thread pool. Guessing would only re-run old experiments, so I started with a profile.
Where a member page spends its time#
The setup, the same for every number below: a Xeon E-2236 (6 cores / 12 threads, 62 GB, NVMe RAID0), Ubuntu 26.04, PHP 8.5, Angie, MariaDB, Valkey, and XenForo 2.3.13 with 200 threads and 2,600 posts. Load comes from
wrkover loopback TLS with 100 connections, logged in as a forum member. CPU mitigations were off for this cycle.Per-service CPU per request, from each service’s cgroup counters during the member thread tier:
That is what “PHP-bound” looks like. Then
perf record -aduring the same load, grouped by library:zlib, 12 % of every sample on the machine, all of it inside PHP. (The
[JIT] tidlines are mostly the PHP interpreter itself, not JIT output:opcache.huge_code_pagescopies the binary’s code onto anonymous huge pages, and perf can no longer name it.)The application was compressing its own pages#
XenForo gzips every page itself, at level 9, whenever the request’s
Accept-Encodingmentions gzip. One curl per header against a member page tells you who did the work:What stung is that I had fixed this before. Three days ago I measured the split: guests keep XenForo’s gzip, because the page cache stores that compressed body once and every hit reuses it; members get plain HTML that the web server compresses. But I shipped the fix as a small block appended to each forum’s
src/config.php, and onlysetup.sh --optimizewrites it. A forum installed after the server, which is the normal order, ran XenForo’s level-9 gzip for every member until someone happened to run--optimize. This cycle’s own test deployment was one of them.The fix belongs where the decision already lives: in the web server. The uncached XenForo handler now withholds the header from PHP:
PHP sees no
Accept-Encoding(a probe script printedNULL), sends plain HTML, and Angie compresses it with Brotli or gzip at level 4, outside the PHP pool. The cached-guest location still passes the cache key’s encoding, so cache hits keep serving XenForo’s stored gzip and are never compressed twice. The configuration tree is copied by both a fresh install and--optimize, so one changed file reaches new servers and running ones alike, and nothing in any forum directory gets edited.The numbers#
Same host, same forum, old and new handler swapped inside each round and the order rotated each round, three rounds, all twelve tiers, with the CPU clock pinned (more on that below):
The spreads did not overlap: the thread page ran 260–264 req/s before and 284–285 after. Per thread page, PHP went from 41.6 to 34.7 ms of CPU. Angie picked up about 2 ms for Brotli, so the whole server still does 10 % less work per page (45.5 → 40.8 ms). Brotli at level 4 is a fraction of what level-9 gzip costs, and it runs in Angie’s event loop instead of holding one of only twelve PHP workers. The bytes barely moved: 17.6 KB from XenForo’s gzip 9, 17.1 KB from Angie’s Brotli 4.
The clock that lied#
Halfway through, the numbers jumped. After a PHP-FPM restart the member tiers read 594 and 361 req/s, against 510 and 285 just before, with no configuration change. For an hour I chased a “long-lived worker” theory: JIT buffer exhaustion, heap fragmentation, persistent connections. The JIT buffer was fine (XenForo uses under 1 MB of the 64 MB), and a mixed WordPress/Chevereto load did not slow XenForo down.
Then I printed the CPU clock next to each run:
PHP’s CPU per request follows the clock exactly: 4.5 / 4.1 = 1.10 = 30.0 / 27.4. This CPU’s turbo is limited by power, not temperature. It may draw 112 W for a while (PL2), then has to drop to 80 W (PL1), which means 4.1 GHz with all cores busy and lower still after a heavy run. The thermal throttle counters were zero and the package sat at 35 °C. My “restart effect” was the preceding test letting the box idle, which refilled the turbo budget for whatever ran next. It is also why, two cycles ago, whichever variant ran first in a block always looked 16–24 % better.
The fix is boring: pin the ceiling below the sustained all-core clock while benchmarking.
At 3.6 GHz, two back-to-back runs read 285 and 286. The test harness now does this (
set-clock.sh), and every benchmark row prints the mean clock beside the result. If your benchmark box turbos, its results come out in GHz, not in config changes.What did not make it#
Three other ideas were measured and dropped:
USE_ZEND_ALLOC_HUGE_PAGES=1). The host already runs THP inmadvisemode, so only PHP’s request heap would get 2 MB pages. A single request worked. Under 100 connections the pool stopped answering: 0–5 req/s and 60 timeouts, in all three rounds. Not shipped, and now written down so nobody tries it again.Zero-error, as usual#
Fresh install in 2:36 with 0 warnings; 1,496 unit checks, 227 dry runs, 67/67 security probes, 86/86 guest-cache cookie cases, functional suite 0 unexpected. Two new regression checks: one asserts the handler withholds the header (and the cached location does not), and one requests a member page with
br, gzipand requires Brotli back, which only Angie produces.--optimizeon a server with the old handler rolled the change out, and a second--optimizechanged 0 of 3,034 recorded settings. The test host went back to its pristine 696-package manifest with 0 changed files under/etc. The first restore attempt left behind the 8 GB swap file that--purgekeeps on purpose, so the restore tool now removes it.What I would tell the next person#
perf report --sort dsoto find, and one line to fix.