Beware that only existing files can be invalidated.
Instead of removing a file from opcache that you have delete, you need to call opcache_invalidate before deleting it.
(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL ZendOpcache >= 7.0.0)
opcache_invalidate — Invalide un script mis en cache
Cette fonction invalide un script particulier depuis le cache opcode.
Si le paramètre force
n'est pas défini ou vaut false
,
le script ne sera invalidé que si la date/heure de modification du script
est plus récente que l'opcode en cache.
Cette fonction n'invalide que le cache en mémoire et non le cache fichier.
filename
Le chemin vers le script à invalider.
force
Si vaut true
, le script sera invalidé indépendamment du fait que
l'invalidation soit nécessaire ou non.
Retourne true
si le cache opcode pour le filename
a été invalidé, ou s'il n'y avait rien à invalider, ou bien false
si le cache opcode est désactivé.
Beware that only existing files can be invalidated.
Instead of removing a file from opcache that you have delete, you need to call opcache_invalidate before deleting it.
opcache_invalidate tries to acquire SHM lock. When the lock can not be acquired opcache_invalidate will return FALSE. During multiple concurrent opcache_invalidate calls with higher probability, the function will return FALSE.
Note that invalidation doesn't actually evict anything from the cache, it just forces a recompile. You can verify this by calling opcache_get_status() and seeing that the invalidated script is not actually removed from "scripts". This means it cannot be used as a more graceful alternative to opcache_reset() when the cache is full ("cache_full":true in status). The cache will eventually fill up and refuse to cache new requests if you do atomic deployment of PHP code by changing the web server's document root. It appears opcache_reset() is the only way to prevent this, but opcache_reset() can disable the cache for any amount of time while attempting to restart, causing load spikes.