Skip to content

Let OPcache cache files written after startup with BREF_LOOP_MAX - #2233

Open
aran112000 wants to merge 1 commit into
brefphp:masterfrom
aran112000:opcache-file-update-protection
Open

aran112000 wants to merge 1 commit into
brefphp:masterfrom
aran112000:opcache-file-update-protection

Conversation

@aran112000

Copy link
Copy Markdown
Contributor

Fixes #2232, which has a reproduction and measurements.

With BREF_LOOP_MAX, OPcache never caches PHP files written after the process started (e.g. Blade views compiled in /tmp), so they are compiled again on every include.

This sets opcache.file_update_protection=0 at the start of the function runtime when BREF_LOOP_MAX is above 1, unless it's set in php.ini. Only 0 works: any other value counts from the process start, so a file written later is always "too new".

The protection is there to avoid caching a file that is still being written. In a long-running process, the file is written by the same process before it's included. Symfony's PhpFilesAdapter already works around this protection by dating its files 10 seconds before the request start.

One side effect: OPcache compares mtimes to the second, so a cached file rewritten within the same second isn't seen as changed, and with the default file cache the old version stays in /tmp until the file changes again. With the shared memory cache and the default revalidate_freq, a long-running process already never revalidates files (revalidate_freq also counts from the request start), so files written after startup now behave like the others. Compiled views and containers are written once, which is why I kept this to BREF_LOOP_MAX rather than the layers' php.ini.

The new test fails without the change. I also checked that with ini_set() at startup, a file written later is cached in bref/arm-php-85:3.

OPcache doesn't cache a file modified less than 2 seconds before the request
started (opcache.file_update_protection). In the CLI, the request starts with
the process, so with BREF_LOOP_MAX every PHP file written after startup (e.g.
views compiled in /tmp) was compiled again on every include.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPcache never caches files written after startup with BREF_LOOP_MAX

1 participant