CakeFest 2017 NYC, the Official CakePHP Conference


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

opcache_invalidateInvalidates a cached script


boolean opcache_invalidate ( string $script [, boolean $force = FALSE ] )

This function invalidates a particular script from the opcode cache. If force is unset or FALSE, the script will only be invalidated if the modification time of the script is newer than the cached opcodes.



The path to the script being invalidated.


If set to TRUE, the script will be invalidated regardless of whether invalidation is necessary.

Return Values

Returns TRUE if the opcode cache for script was invalidated or if there was nothing to invalidate, or FALSE if the opcode cache is disabled.

See Also

add a note add a note

User Contributed Notes 2 notes

joel at taotesting dot com
2 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.
kaare at colourbox dot com
11 months 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.
To Top