PHP 7.4 was released a few days ago and it's the most exciting PHP release in years. It includes game-changing features such as typed properties, arrow functions, covariant types, FFI (Foreign Function Interface), OPCache preloading and more.

OPCache Preloading¶

At the very beginning, PHP parsed and compiled any file used to serve a request. The parsing/compiling result (called "opcodes") was not reused for other requests, so the exact same process had to be repeated again and again.

On production servers, the code of your PHP files does not change between requests, so the parsing and compiling result can be reused. That's what the OPCache does (OPCache = "opcodes cache"), improving the overall performance between 2 and 15 times.

However, the OPCache doesn't remove other execution costs: PHP still has to check if the source file was modified, copy certain parts of classes and functions from the shared memory cache to the process memory, etc. Moreover, since each PHP file is compiled/cached completely independently from any other file, PHP can't resolve dependencies between classes stored in different files and has to re-link the class dependencies at run-time on each request.

PHP 7.4 can eliminate most of these costs thanks to preloading. On server startup - before any application code is run - PHP can load a certain set of PHP files into memory and make their contents permanently available to all subsequent requests.