opcache_invalidate

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL ZendOpcache >= 7.0.0)

opcache_invalidate β€” АннулируСт Π·Π°ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ скрипт

ОписаниС

function opcache_invalidate(string $filename, bool $force = false): bool

Ѐункция Π°Π½Π½ΡƒΠ»ΠΈΡ€ΡƒΠ΅Ρ‚ скрипт Π² кСшС ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° Π² ΠΎΠ±Ρ‰Π΅ΠΉ памяти. ΠŸΡ€ΠΈ пропускС Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π° force ΠΈΠ»ΠΈ ΠΏΡ€ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡Π΅ Π² Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π΅ значСния false скрипт аннулируСтся, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли врСмя измСнСния скрипта Π½ΠΎΠ²Π΅Π΅ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ измСнСния Π·Π°ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Ρ… ΠΎΠΏΠΊΠΎΠ΄ΠΎΠ². ΠŸΡ€ΠΈ Π²ΠΊΠ»ΡŽΡ‡Ρ‘Π½Π½ΠΎΠΉ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Π΅ opcache.file_cache функция Ρ‚Π°ΠΊΠΆΠ΅ Π°Π½Π½ΡƒΠ»ΠΈΡ€ΡƒΠ΅Ρ‚ запись Π² Ρ„Π°ΠΉΠ»ΠΎΠ²ΠΎΠΌ кСшС.

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

filename
ΠŸΡƒΡ‚ΡŒ ΠΊ скрипту, кСш ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ трСбуСтся Π°Π½Π½ΡƒΠ»ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ.
force
ΠŸΡ€ΠΈ установкС значСния true кСш скрипта ΠΏΡ€ΠΈΠ½ΡƒΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ аннулируСтся, Π΄Π°ΠΆΠ΅ Ссли послС добавлСния Π² кСш скрипт Π½Π΅ измСнялся.

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ true ΠΏΡ€ΠΈ Π°Π½Π½ΡƒΠ»ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ кСша ΠΎΠΏΠΊΠΎΠ΄ΠΎΠ² Ρ„Π°ΠΉΠ»Π° ΠΏΠΎ ΠΏΡƒΡ‚ΠΈ filename ΠΈΠ»ΠΈ Ссли Ρ„Π°ΠΉΠ» Π½Π΅ ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Π»ΡΡ. ΠŸΡ€ΠΈ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡Ρ‘Π½Π½ΠΎΠΌ ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° возвращаСтся false.

Π‘ΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Ρ‚Π°ΠΊΠΆΠ΅

  • opcache_compile_file() - ΠšΠΎΠΌΠΏΠΈΠ»ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΈ ΠΊΠ΅ΡˆΠΈΡ€ΡƒΠ΅Ρ‚ PHP-скрипт Π±Π΅Π· исполнСния
  • opcache_reset() - БбрасываСт содСрТимоС кСша ΠΎΠΏΠΊΠΎΠ΄ΠΎΠ²
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 3 notes

up
13
joel at taotesting dot com ΒΆ
11 years ago
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.
up
10
kaare at colourbox dot com ΒΆ
10 years ago
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.
up
8
dmitry dot balabka at gmail dot com ΒΆ
6 years ago
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.