opcache.preload: can these be actually invalidated/reloaded?
| From: | Raphaël | Date: | Thu, 06 Mar 2025 00:40:00 +0000 |
| Subject: | opcache.preload: can these be actually invalidated/reloaded? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-328645@lists.php.net to get a copy of this message | ||
Dears,
Is it possible to invalidate (and recompile) scripts preloaded via
opcache.preload ?
Simple example (PHP 8.3)
```
> <?php
> // a.php
> // opcache.enable=1
> function r () { die("1"); };
> r();
```
Without preloading, no problem. opcache works and script can be invalidate/reloaded.
Now, with opcache.preload=preload.php simply written as:
> <?php opcache_compile_file("a.php");
it still work, after restarting php-fpm: opcache'ed.
*But* now, simulating a code update, I call opcache_invalidate("a.php");
(from the same cgi context/SAPI = FPM)
But then the next compilation (whether regular page load or warmup/opcache_compile_file())
leads to:
> Fatal error: Cannot redeclare r()`
> [...]
> "Zend OPcache could not compile file"
And the number of cache hits in opcache-status sticks to its last known value before invalidation.
Only a full reset would now reload that script: I found no way to invalidate specifically this
script.
I understand invalidation != eviction, but then how can I avoid this "redeclare" problem
if
no eviction happens ? And how to "reset" an individual item preload using opcache.preload?
(I tried dups_fix=1 without success)
I guess it's the redeclaration Fatal error which cause Zend to complain.
But why is the function still part of the defined symbols after invalidation just happened
and how to get this item reloaded.
It sounds to me like if opcache_invalidate() couldn't act upon items preloaded by the
process manager itself contrary to these cached by the pool (here using "ondemand")
Thank you for your insights