> ## Content Index
> Fetch the complete content index at: https://sudosecurity.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# PHP OPcache, Preloading and the JIT, Measured on Laravel: One Setting Is 18x, One Costs You 19%, and the JIT Does Nothing
- URL: https://sudosecurity.org/php-opcache-jit-preloading-benchmarks/
- Published: 2026-12-01T18:00:00.000Z
- Updated: 2026-12-01T18:00:00.000Z
- Description: I ran Laravel 13 on PHP 8.6 FPM under six OPcache configurations and timed every one. OPcache itself was worth 18x, revalidate_freq=0 quietly cost 19%, preloading added 9%, and the JIT that doubles Zend's CPU benchmark moved a real page by 1%.
- Author: Santhdium
- Tags: PHP, Performance, NGINX, Web Servers, Backend Development, Frameworks and Libraries, Docker, Compilers

Every PHP performance thread eventually turns into a pile of `php.ini` lines pasted from somebody's 2019 blog post. `opcache.jit=1255`. `opcache.validate_timestamps=0`. `opcache.memory_consumption=512`. Nobody in the thread has measured any of them on their own app, and half of them were written for PHP versions that no longer exist.

So I measured. Laravel 13.43 on PHP 8.6.0 FPM behind nginx, six OPcache configurations, three rounds each, all under the same load. The results come down to one setting that matters enormously, one you can get wrong in a way that costs real throughput, one that helps a little, and one that helps your benchmark far more than your users.

## PHP OPcache Settings That Matter, in One Table

Here's the whole result up front. Requests per second for Laravel's welcome page, the median of six samples (three rounds of two 3,000-request runs, `ab -c 4`), with the image's built-in defaults as the baseline:

```text
a-off           median    25.9 req/s  min    25.1  max    28.6  vs default -95%
b-default       median   477.8 req/s  min   469.0  max   490.5  vs default +0%
c-revalidate0   median   386.4 req/s  min   368.6  max   425.6  vs default -19%
d-novalidate    median   483.5 req/s  min   457.5  max   529.7  vs default +1%
e-preload       median   519.8 req/s  min   484.6  max   555.3  vs default +9%
f-jit           median   483.3 req/s  min   458.7  max   500.9  vs default +1%

```

| Config        | What changed                         | req/s | vs default |
| ------------- | ------------------------------------ | ----- | ---------- |
| a-off         | opcache.enable=0                     | 25.9  | −95%       |
| b-default     | nothing (no php.ini at all)          | 477.8 | —          |
| c-revalidate0 | opcache.revalidate\_freq=0           | 386.4 | −19%       |
| d-novalidate  | opcache.validate\_timestamps=0       | 483.5 | +1%        |
| e-preload     | d + opcache.preload of the framework | 519.8 | +9%        |
| f-jit         | d + opcache.jit=tracing              | 483.3 | +1%        |

Each of those rows has a story, and a couple of them run against what you've been told.

## The Rig, and the Bug in My First Run

The setup: the official `php:8.6-fpm` image with a static pool of four children, `nginx:alpine` in front, both on host networking on a 2-vCPU VM. Laravel was installed with `composer install --no-dev --optimize-autoloader`, then `config:cache`, `route:cache` and `view:cache`, with `APP_ENV=production` and `APP_DEBUG=false`. That's the setup the Laravel docs tell you to deploy with. Each configuration got a fresh FPM container, a 300-request warm-up, then the timed runs.

My first pass produced garbage, and how it went wrong is worth knowing. Throughput fell every round: the default config did 407 req/s, then 222, then 126\. Nothing in PHP changed between rounds. The cause was Laravel's `file` session driver: every anonymous request to the welcome page writes a session file, and after an hour of benchmarking `storage/framework/sessions` held **126,381 files**. Session garbage collection was scanning that directory on a random fraction of requests. I switched the benchmark to the `array` session driver to take sessions out of the measurement. In production, the lesson is that file sessions on a busy site are a slow leak, and Redis or the database driver doesn't have that problem.

The other early surprise: my first preloading run reported 2,500 req/s, five times faster than anything else. Every response was 381 bytes long. The preload script had loaded Composer's autoloader through a different path (`/bench/app/...`) than the one FPM served the app from (`/app/...`). PHP treated them as two different files, declared the autoloader class twice, and every request died with a fatal error. A fatal error is very fast. If a tuning change gives you an unbelievable number, check the response body before you celebrate.

## OPcache Itself: 18x, and It's On by Default

Turning OPcache off took Laravel from 477.8 to 25.9 req/s. Without it, PHP parses and compiles every one of the 429 files this page touches, on every request. With it, the compiled opcodes sit in shared memory and every FPM child reuses them. OPcache reported a 99.98% hit rate and 21.7 MB of shared memory used.

You almost certainly have it on already. PHP 8.5's UPGRADING notes say "the Opcache extension is now always built into the PHP binary and is always loaded," and `opcache.enable` defaults to 1\. The way people end up without it is copying a dev config into production, or running a long CLI worker. `opcache.enable_cli` defaults to 0, so queue workers and `artisan` commands compile everything from scratch unless you turn it on.

The capacity defaults held up fine for this app:

| Directive                         | Default (php.net) | What this Laravel app used                |
| --------------------------------- | ----------------- | ----------------------------------------- |
| opcache.memory\_consumption       | 128 (MB)          | 21.7 MB, or 52.7 MB with preloading       |
| opcache.max\_accelerated\_files   | 10000             | 429 scripts, or 2,898 with preloading     |
| opcache.interned\_strings\_buffer | 8 (MB)            | 4.4 MB, and **8 of 8 MB with preloading** |

That last row is the one to watch. Preloading filled the interned-strings buffer completely. When it's full, OPcache stops sharing new strings between workers, and each process keeps its own copies. If you preload, raise `opcache.interned_strings_buffer` (I'd start at 32). As a user note on the php.net configuration page points out, that buffer is carved out of `memory_consumption`, not added on top of it, so 128 MB total with a 32 MB buffer leaves 96 MB for bytecode.

> **We recommend reading** [PHP API Performance: N+1 Queries, cURL, and Connection Pools](https://sudosecurity.org/php-api-rebuild-why-it-was-slow/) to continue reading our selection of content. Once OPcache is sorted, the next bottlenecks are usually in your own code, and this walks through four of them.

[PHP API Performance: N+1 Queries, cURL, and Connection Pools](https://sudosecurity.org/php-api-rebuild-why-it-was-slow/) A PHP API case study: fixing an N+1 query, twenty serial cURL calls, missing connection pooling, and stats recalculated on every request with Redis caching. SudoSecurity · Santhdium

## revalidate\_freq=0: The 19% You Pay for Convenience

`opcache.validate_timestamps=1` (the default) means OPcache checks whether a file changed on disk before using its cached version. `opcache.revalidate_freq` sets how often it checks. The default is 2 seconds, and per the docs, "0 will result in OPcache checking for updates on every request."

`revalidate_freq=0` is the setting people use in development so their edits show up right away. Then the dev config ends up in a Docker image, and every request `stat()`s every file it includes. On this app that's 429 extra filesystem calls per page, and it cost 19% throughput: 386.4 req/s against 477.8\. On a network filesystem or a container with an overlay filesystem under load, expect worse.

## validate\_timestamps=0: Faster in Theory, a Deploy Trap in Practice

Turning validation off entirely is the classic production tip, and it came in at +1%, inside the noise. With the 2-second default, OPcache only checks each file once every two seconds anyway, so there's almost nothing left to save.

What you do get is a behavior change. Here's a test where I edited a file under a running FPM pool with `validate_timestamps=0`:

```bash
for i in 1 2 3 4; do curl -s http://127.0.0.1:8080/ver.php; done | sort | uniq -c | sed 's/^/before edit: /'
echo '<?php echo "v2\n";' > $D/app/public/ver.php
sleep 3
for i in 1 2 3 4; do curl -s http://127.0.0.1:8080/ver.php; done | sort | uniq -c | sed 's/^/after edit, 3 s later: /'
docker kill -s USR2 fpm >/dev/null; sleep 2
for i in 1 2 3 4; do curl -s http://127.0.0.1:8080/ver.php; done | sort | uniq -c | sed 's/^/after kill -USR2 (graceful reload): /'

```

```text
before edit:       4 v1
after edit, 3 s later:       4 v1
after kill -USR2 (graceful reload):       4 v2

```

The edit was invisible until FPM reloaded. That's what the docs say will happen: "you must reset OPcache manually via opcache\_reset(), opcache\_invalidate() or by restarting the Web server." It's fine if your deploy always restarts or reloads FPM, which immutable containers do by definition. It's a production incident waiting to happen if somebody deploys with `git pull` or `rsync` and assumes the change is live. For a 1% gain on a typical framework app, I'd only turn it off where deploys already replace the container.

PHP 8.5 added a related option for exactly that case: `opcache.file_cache_read_only`, for "read-only file systems (e.g. read-only Docker containers)," which the UPGRADING notes say is best combined with `validate_timestamps=0`, `enable_file_override=1` and `file_cache_consistency_checks=0`.

## Preloading: Real, Modest, and Fiddly

Preloading (PHP 7.4+) runs a script once when FPM starts and keeps every class it loads in shared memory, already linked, for every request. Here's the script I used. It walks Composer's optimized classmap and autoloads everything under `laravel/framework` and `symfony`:

```php
<?php
// Paths must match the ones FPM serves (/app), or the autoloader is declared twice.
// Preload every class in Composer's optimized classmap that lives under laravel/framework or symfony.
$classmap = require '/app/vendor/composer/autoload_classmap.php';
require '/app/vendor/autoload.php';
$n = 0;
foreach ($classmap as $class => $file) {
    if (!str_contains($file, '/laravel/framework/') && !str_contains($file, '/symfony/')) {
        continue;
    }
    try {
        if (class_exists($class) || interface_exists($class) || trait_exists($class)) {
            $n++;
        }
    } catch (Throwable $e) {
        // some classes depend on optional packages; skip them
    }
}
error_log("preloaded $n classes");

```

```ini
opcache.validate_timestamps=0
opcache.preload=/bench/preload.php
opcache.preload_user=www-data

```

It loaded 2,664 classes from 2,844 files and logged 95 "Can't preload unlinked class" warnings, mostly for classes whose parent comes from a package that isn't installed (Mercure broadcasting, PHPUnit test cases). Those are harmless. The payoff was +9% over the default, 519.8 req/s, and the cost was 31 MB more shared memory and a full interned-strings buffer.

The trade-offs the manual spells out are real. Preloaded code "requires restarting the PHP process to clear," so you can't hot-patch it. "Preload everything may be the easiest strategy, but not necessarily the best." And as my first run showed, paths have to match exactly what FPM serves. For a framework app at steady load, 9% is worth having if your deploys already restart FPM. For anything else, it's a lot of moving parts for 9%.

## The JIT: 2x on the Benchmark, 1% on the Page

PHP 8.4 changed the JIT defaults. Per php.net, `opcache.jit` now defaults to `disable`, where it was `tracing` before 8.4, and `opcache.jit_buffer_size` defaults to 64M where it was 0\. In practice the JIT stays off until you set `opcache.jit=tracing` yourself.

When you do, here's what Zend's own `bench.php` does on PHP 8.6.0 CLI, disabled vs tracing, in seconds per test:

```text
simple            0.004    0.001
simplecall        0.003    0.001
simpleucall       0.003    0.000
simpleudcall      0.003    0.001
mandel            0.019    0.006
mandel2           0.035    0.007
ackermann(7)      0.011    0.007
ary(50000)        0.004    0.004
ary2(50000)       0.003    0.003
ary3(2000)        0.033    0.006
fibo(30)          0.033    0.021
hash1(50000)      0.005    0.005
hash2(500)        0.005    0.005
heapsort(20000)    0.013    0.009
matrix(20)        0.011    0.005
nestedloop(12)    0.012    0.005
sieve(30)         0.005    0.003
strcat(200000)    0.002    0.003
------------------------                  
Total             0.204    0.090

```

Total: 0.204 seconds without the JIT and 0.090 with it, so 2.3x faster. Over three runs each, disabled ranged 0.144–0.209 s, tracing 0.086–0.089 s, and function mode 0.085–0.089 s. The big wins are in tight numeric loops: `mandel2` went 5x faster, `ary3` 5.5x. The tests that mostly call into C functions (`hash1`, `hash2`, `ary`, `strcat`) didn't move at all.

Then I turned on the same tracing JIT under Laravel: 483.3 req/s against 483.5 without it. Zero, within noise. It also took another 4.9 MB of shared memory.

That's the whole JIT story for web apps. A framework request spends its time in hash table lookups, string handling, autoloading, routing and C functions, not in arithmetic loops. The JIT speeds up the PHP bytecode, and most of the time in a framework request isn't spent in PHP bytecode. If you're doing image math, parsing, simulations or crypto in pure PHP, try it. Otherwise it's extra machine code in shared memory and another layer to suspect when something segfaults. As of PHP 8.4, the docs also note, "if JIT is enabled, PHP exits with a fatal error during startup when JIT initialization fails," so a misconfigured buffer is no longer silently ignored.

> **We recommend reading** [PHP 8.6 Finally Turns On the Session Settings You Were Told to Set in 2006](https://sudosecurity.org/php-8-6-new-features-security-defaults/) to continue reading our selection of content. The defaults that did change in 8.6 are the session ones, and they're worth checking against your config.

[PHP 8.6 Finally Turns On the Session Settings You Were Told to Set in 2006](https://sudosecurity.org/php-8-6-new-features-security-defaults/) PHP 8.6 ships November 19, 2026 with secure session defaults, a php://filter chain limit, mysqli::quote\_string(), and partial application. SudoSecurity · Santhdium

## Cold Starts: The First Request After Every Deploy

Throughput numbers describe a warm server. Containers spend real time cold, though: every deploy, every autoscale event and every crashed pod brings up an FPM with empty shared memory, and its first request compiles everything that request touches. I timed requests 1 to 5 against a freshly started FPM, three rounds each:

```bash
first() {   # time the first request, then the next four
  local out=""
  for i in 1 2 3 4 5; do out="$out $(curl -s -o /dev/null -w '%{http_code} %{time_total}' http://127.0.0.1:8080/ | awk '{printf "%.1f%s", $2*1000, ($1==200 ? "" : "(HTTP " $1 ")")}')"; done
  echo "$out"
}
echo "ms per request, requests 1-5 after a fresh FPM start:"
start $D/ini/d-novalidate.ini; echo "  shared memory only (default)     $(first)"
start $D/ini/g-filecache.ini;  echo "  file_cache, empty (first boot)   $(first)"
start $D/ini/g-filecache.ini;  echo "  file_cache, warm (after restart) $(first)"
start $D/ini/e-preload.ini;    echo "  preload                          $(first)"

```

The file-cache config is two lines:

```ini
opcache.validate_timestamps=0
opcache.file_cache=/opcache-file

```

```text
ms per request, requests 1-5 after a fresh FPM start:
  shared memory only (default)      182.9 7.4 7.2 6.5 3.1
  file_cache, empty (first boot)    258.4 6.5 5.7 5.7 4.0
  file_cache, warm (after restart)  38.5 9.1 8.4 8.0 3.5
  preload                           33.1 6.9 6.8 6.6 3.9
file_cache on disk: 428 files, 16M
ms per request, requests 1-5 after a fresh FPM start:
  shared memory only (default)      173.8 8.6 6.6 6.9 3.5
  file_cache, empty (first boot)    294.1 8.0 6.9 5.6 3.9
  file_cache, warm (after restart)  36.2 8.4 7.5 6.3 3.0
  preload                           25.6 8.1 6.8 5.5 2.8
file_cache on disk: 428 files, 16M
ms per request, requests 1-5 after a fresh FPM start:
  shared memory only (default)      176.6 7.3 6.9 6.8 3.5
  file_cache, empty (first boot)    315.7 8.1 7.1 6.3 3.3
  file_cache, warm (after restart)  35.0 9.5 7.3 7.7 4.1
  preload                           30.8 7.5 6.9 6.6 3.8
file_cache on disk: 428 files, 16M

```

| First request after FPM starts                             | Round 1  | Round 2  | Round 3  |
| ---------------------------------------------------------- | -------- | -------- | -------- |
| Shared memory only (validate\_timestamps=0, no file cache) | 182.9 ms | 173.8 ms | 176.6 ms |
| opcache.file\_cache, empty                                 | 258.4 ms | 294.1 ms | 315.7 ms |
| opcache.file\_cache, warm from a previous run              | 38.5 ms  | 36.2 ms  | 35.0 ms  |
| Preload                                                    | 33.1 ms  | 25.6 ms  | 30.8 ms  |

By the second request, every configuration is down to 6–9 ms. The difference is entirely in that first hit: about 175 ms of compiling 429 files, cut to 25–38 ms by either a warm file cache or preloading. An empty file cache makes the first request slower still, 260–315 ms, because OPcache compiles and also writes 428 `.bin` files (16 MB here) to disk.

Two ways to use this:

- **Preloading** pays the compile cost during FPM startup instead of on a user's request, which is the strongest argument for it in an autoscaling setup. In the throughput test it was worth 9%. On the first request after a deploy, it's worth about 150 ms.
- **A file cache baked into the image.** Run the app once during the image build to fill `opcache.file_cache`, then ship it read-only with PHP 8.5's `opcache.file_cache_read_only`. The UPGRADING note warns that "a cache generated with a different build of PHP, a different file path, or different settings ... may be ignored," so build the cache in the same image and at the same paths you'll run. I didn't test the read-only variant here; the warm-cache row above is the effect it's designed to give you.

The warm-up script you'd normally write to hit a few URLs before adding a pod to the load balancer does the same job. But a readiness probe that hits `/` is already doing it, and it means the first real user never pays the 175 ms.

## What I'd Actually Ship

For a typical framework app in containers, where every deploy replaces the container:

```ini
opcache.enable_cli=1
opcache.validate_timestamps=0
opcache.interned_strings_buffer=32

```

The first line is for queue workers and scheduled commands. The second is safe only because the container is replaced on every deploy. The third matters most if you preload. Leave `memory_consumption` and `max_accelerated_files` at their defaults until `opcache_get_status()` shows you're near them. Add preloading if you've measured a gain and your deploys restart FPM. Leave the JIT off unless your hot path is CPU math. And never ship `revalidate_freq=0`.

For anything deployed by changing files in place, keep `validate_timestamps=1` and the 2-second default. You give up about 1%.

## What This Doesn't Cover

- **Database-heavy pages.** Laravel's welcome page touches no database. Real pages that wait on MySQL or Redis will show smaller percentage gains from all of this, because PHP is a smaller share of the request.
- **WordPress, Symfony and Drupal.** File counts and autoloading patterns differ. The method transfers, but the numbers don't.
- **FPM pool tuning.** `pm.max_children` and friends usually matter more than any OPcache knob. That's its own article.
- **FrankenPHP, RoadRunner and Swoole.** Persistent-worker runtimes keep the framework booted between requests, which changes the economics of everything above.
- **Big boxes.** This is two vCPUs. The relative ordering should hold. The absolute numbers won't.

## The Actual Point

OPcache is the one PHP performance setting that changes everything, and it's already on by default. Most of what's left is avoiding self-inflicted wounds: don't ship `revalidate_freq=0`, turn on `enable_cli` for workers, and size the interned-strings buffer if you preload. Preloading is a modest real gain with real operational cost. The JIT is a fine piece of engineering that you probably don't need. Measure your own app the same way, and check the response body before you believe any number that looks too good. Mine didn't check out the first time, and the bug was mine.

*Sources: php.net's OPcache runtime configuration and preloading pages, the PHP 8.5 and 8.6 UPGRADING files in php-src, and `Zend/bench.php` from the PHP-8.6 branch. All benchmarks were run by me on `php:8.6-fpm` (PHP 8.6.0), `nginx:alpine` and Laravel 13.43.0\. The preload script, the configs and the test scripts are original code using PHP's documented OPcache API; every output block is copied from those runs, except the "What I'd Actually Ship" block, which is a recommended starting config I didn't benchmark as a set.*