Reputation: 13558
For opcode cache (php 5.5) invalidation I wrote a small script. However, the status does tell me the invalidation failed. How does this happen?
<?php
$scripts = opcache_get_status(true)["scripts"];
$failures = array();
foreach (array_keys($scripts) as $file) {
$result = opcache_invalidate($file, true);
if (!$result) $failures[] = $file;
}
if(count($failures) !== 0) {
exit("Failed to clear OPcache for files " . implode(", ", $failures));
}
echo sprintf("%s OPcache files cleared\n", count($scripts));
$scripts = opcache_get_status(true)["scripts"];
echo sprintf("There are still %s files in the cache", count($scripts));
It's now a very simple script (which will be part of Soflomo\Cache). My problem is that the first echo ("x OPcache files cleared for web") prints the same number as the last echo ("There are still x files in the cache") statement!
How to reproduce:
560 OPcache files cleared
There are still 560 files in the cache
Can anyone explain this? And are the files cleared for sure, or not?
PS. I know the above could be replaced by opcache_reset()
, but the script will filter on a certain subset of files as a next step. It is meant to clear the opcode for files from a single application, even if there are multiple applications running on a single server. The reset will clear all those files, which isn't an option.
Upvotes: 1
Views: 1955
Reputation: 48357
Opcache does not evict invalid items from memory - they stay there until the pool is full at which point the memory is completely cleared. Existence of an invalid cache entry does not prevent PHP loading/compiling the file again.
Upvotes: 3