OPcache Functions in PHP
PHP OPcache is a bytecode caching system that increases the performance of your web application. It does so by storing precompiled bytecode which eliminates the need to load and parse the script on each request. This results in significant reductions of the time to load your Website.
OPcache is installed and activated by default with PHP version 5.5+. It replaces the APC caching system that was previously included with PHP. Its functionality is similar to APC, but it is formally endorsed by the PHP developers which is an important indication of stability and a large working community.
One of the most important functions in opcache is opcache_invalidate(). This function clears the opcode cache for a specific script. The script is identified by the path to the file as well as the extension. Invalidation can be forced if the parameter $force is set. The function returns TRUE if the invalidation was successful and FALSE otherwise.
Another important opcache function is opcache_get_status(). This function returns information about the opcode cache’s state including memory usage, hit and miss rates and other useful data. Using this function is an excellent way to monitor your opcode cache to identify bottlenecks and optimize the configuration.
If you run a high volume of scripts that use the opcode cache, it can become full. This can cause the thundering herd effect, where a lot of requests are made simoultaneously generating the same cache entries, and can result in the cache becoming unusable. In this case it is recommended to reset the opcode cache by calling opcache_reset().