PHP 7.4 came out on November 28; as of the day I'm writing this, it's a fresh three-week-old release. While everyone was looking at typed properties and arrow functions in the changelog, my eye was stuck on a single line: opcache.preload. The promise: load your application's classes once when PHP-FPM starts, and get rid of the cost of linking them again on every request. Performance claims of 30-50 percent were flying around in the RFC discussions. The API layer of our fleet platform was PHP, and every millisecond meant fresher data on the map screen. We set aside a weekend and measured it with our real workload. The numbers are below; first, let me temper expectations a bit.
We Already Had OPcache; What Does Preload Change?
There's a lot of conceptual confusion here, so it needs clearing up. For years OPcache has kept the compiled form of PHP files (opcodes) in shared memory; even before 7.4, nobody was recompiling files on every request. What preload adds isn't savings on compilation but savings on linking. Normally, on every request, the autoloader kicks in when a class is first used, and even if the opcodes come from the cache, the class's internal representation is built: it gets merged with its parent class, its interfaces are verified, its traits are copied and its constants are resolved. Preload does this work once in the FPM master process and makes the already-linked classes permanently available to all workers. The autoloader never runs for those classes, because the class already "exists."
So your gain depends on how many classes you touch per request and on the inheritance/trait complexity of those classes. In a three-class microservice, preload gains you nothing. On a fat request path that loads 400 classes, it's noticeable.

The Thorny Parts of the Setup
On the php.ini side it's two lines: opcache.preload is the path to the script, and opcache.preload_user is mandatory because FPM starts as root (it refuses to run preload as root; we gave it www-data). The real issue is the preload script itself. There are two strategies: compile the files one by one with opcache_compile_file(), or actually load them with require_once. With the first, you don't have to care about dependency order, but a class may not count as "fully linked"; with the second, full linking is guaranteed, but if you try to load a class whose parent class hasn't been preloaded, the script blows up. We chose the require_once route and wrote an 80-line script that reads Composer's classmap and arranges the classes in topological order. In the first three attempts we got three different "Class not found" errors; the culprit every time was old-style classes defined conditionally (inside an if class_exists block). We moved those from the preload list to a blacklist.
One more trap: what happens when a preloaded file changes? Nothing. The workers keep living with the old version; the only way to pick up the change is to restart FPM. Even opcache_reset() doesn't touch the preloaded part. A mandatory FPM reload was added to our deployment script, and that made us revisit our zero-downtime deployment setup. Preload is the official funeral of the "change the code, hit F5" habit; that's why we keep it completely disabled in the development environment.

The Measurement Setup: What We Counted and How
For benchmark hygiene we pinned down three things, because in the first runs two of them misled us. We switched the CPU frequency governor to performance mode; in ondemand mode, the results of the first minute came out 8 percent different from the rest. We turned off opcache.validate_timestamps in both scenarios; in the first run, where we forgot to turn it off, OPcache decorated every request with stat calls and made the no-preload side look unfairly slow. And we ran the tests not back to back on the same machine but alternating the scenarios, so that file cache and warm-up effects would be spread equally across both sides.
The test machine was a production twin: 8 cores, 32 GB RAM, PHP 7.4.0, nginx + FPM (static, 48 workers), with OPcache enabled and warm in both scenarios. So the comparison isn't "OPcache versus preload" but "warm OPcache versus warm OPcache + preload", and that's the honest comparison. For the load, we replayed a real request mix recorded from production: 70 percent vehicle list/last location endpoints (light), 25 percent history queries (medium), 5 percent report triggers (heavy). 10-minute runs with wrk, three repetitions per scenario; I'm reporting the medians.
Preload scope: the framework core + our domain classes, 1,410 files in total. FPM master startup got 1.9 seconds longer, and shared memory usage grew by 96 MB. Both values are too small for us to care about.
The Numbers: Not Fifty Percent, but Thirteen
On the light endpoints, average latency dropped from 11.2 ms to 9.7 ms (13.4 percent). p99 went from 34 ms to 27 ms; the improvement in the tail is bigger than in the average, because it turns out the autoloader's file system stat calls were what made the tail jitter the most. Throughput went up from 4,480 requests/sec to 5,070 requests/sec. On the medium endpoints the gain fell to 7 percent; on the heavy report endpoint it was under 2 percent, indistinguishable from measurement noise. That makes sense: the report endpoint spends its time in the database, and class linking's share is a drop in the bucket.

Out of curiosity, we also made the preload scope a variable: a narrow list that loads only the framework core brought in about two-thirds of the gain on its own. Adding our domain classes contributed the remaining third, but it also brought an operational burden, such as maintaining the blacklist. The bigger you make the scope, the smaller the returns; instead of the "preload everything" reflex, it's smarter to start with the files whose autoload time shows up in the profiler.
So where do the 30-50 percent claims come from? Those measurements are either comparisons without OPcache or "hello world"-level requests whose entire duration is bootstrap. In a real application, preload's share melts away to the extent that the request's time is filled with I/O. Our 13 percent is still a very concrete gain at close to zero cost for a system handling 40 million API calls a day; it just isn't the revolution it's marketed as.
A small but nice side finding: after preload, the RSS memory usage of FPM workers dropped by 9 MB per worker on average. The linked class definitions now live as a single copy in shared memory rather than separately in each worker. With 48 workers, that's a saving of over 400 MB, and that memory went straight to the file system cache.
On the horizon there's also PHP 8's JIT; the RFC has been accepted, and it's coming at the end of 2020. Let me say it now: I think JIT will share preload's fate on typical web workloads, because both shorten the time spent on the CPU, and a typical web request doesn't spend its time on the CPU. It may be a different story for math-heavy work (like our Kalman filter layer); when it comes out, I'll measure it with the same setup.
Since we tried two of 7.4's other new features that same weekend, let me make a note of them. Typed properties are a matter of discipline, not performance; but FFI excites me as a telematics person: being able to call our C library that parses CAN frames from PHP without writing an extension could seriously cut prototyping time. Measuring that is for another post.
Let me wrap up with a summary: we put preload into production and, in exchange for 2 seconds and 96 MB paid once at startup, gained a permanent 10-13 percent in the API layer. In your workload this ratio could come out completely different; don't believe it until you measure it, and when you measure, don't forget to keep OPcache warm on both sides. If you'd like to talk through a preload script design or a measurement setup for your own application, get in touch with me; a weekend benchmark isn't a chore for me, it's a hobby.