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 β ΠΠ½Π½ΡΠ»ΠΈΡΡΠ΅Ρ Π·Π°ΠΊΠ΅ΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠΉ ΡΠΊΡΠΈΠΏΡ
Π€ΡΠ½ΠΊΡΠΈΡ Π°Π½Π½ΡΠ»ΠΈΡΡΠ΅Ρ ΡΠΊΡΠΈΠΏΡ Π² ΠΊΠ΅ΡΠ΅ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° Π² ΠΎΠ±ΡΠ΅ΠΉ ΠΏΠ°ΠΌΡΡΠΈ.
ΠΡΠΈ ΠΏΡΠΎΠΏΡΡΠΊΠ΅ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠ° force ΠΈΠ»ΠΈ ΠΏΡΠΈ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠ΅ Π² Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ false
ΡΠΊΡΠΈΠΏΡ Π°Π½Π½ΡΠ»ΠΈΡΡΠ΅ΡΡΡ, ΡΠΎΠ»ΡΠΊΠΎ Π΅ΡΠ»ΠΈ Π²ΡΠ΅ΠΌΡ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΡΠΊΡΠΈΠΏΡΠ° Π½ΠΎΠ²Π΅Π΅ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ Π·Π°ΠΊΠ΅ΡΠΈΡΠΎΠ²Π°Π½Π½ΡΡ
ΠΎΠΏΠΊΠΎΠ΄ΠΎΠ².
ΠΡΠΈ Π²ΠΊΠ»ΡΡΡΠ½Π½ΠΎΠΉ Π΄ΠΈΡΠ΅ΠΊΡΠΈΠ²Π΅ opcache.file_cache
ΡΡΠ½ΠΊΡΠΈΡ ΡΠ°ΠΊΠΆΠ΅ Π°Π½Π½ΡΠ»ΠΈΡΡΠ΅Ρ Π·Π°ΠΏΠΈΡΡ Π² ΡΠ°ΠΉΠ»ΠΎΠ²ΠΎΠΌ ΠΊΠ΅ΡΠ΅.
filenameforcetrue ΠΊΠ΅Ρ ΡΠΊΡΠΈΠΏΡΠ° ΠΏΡΠΈΠ½ΡΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎ Π°Π½Π½ΡΠ»ΠΈΡΡΠ΅ΡΡΡ,
Π΄Π°ΠΆΠ΅ Π΅ΡΠ»ΠΈ ΠΏΠΎΡΠ»Π΅ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΡ Π² ΠΊΠ΅Ρ ΡΠΊΡΠΈΠΏΡ Π½Π΅ ΠΈΠ·ΠΌΠ΅Π½ΡΠ»ΡΡ.
Π€ΡΠ½ΠΊΡΠΈΡ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ true ΠΏΡΠΈ Π°Π½Π½ΡΠ»ΠΈΡΠΎΠ²Π°Π½ΠΈΠΈ ΠΊΠ΅ΡΠ° ΠΎΠΏΠΊΠΎΠ΄ΠΎΠ² ΡΠ°ΠΉΠ»Π° ΠΏΠΎ ΠΏΡΡΠΈ filename
ΠΈΠ»ΠΈ Π΅ΡΠ»ΠΈ ΡΠ°ΠΉΠ» Π½Π΅ ΠΊΠ΅ΡΠΈΡΠΎΠ²Π°Π»ΡΡ. ΠΡΠΈ ΠΎΡΠΊΠ»ΡΡΡΠ½Π½ΠΎΠΌ ΠΊΠ΅ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π°
Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΡΡΡ false.
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.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.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.