What is OpCache and how can it be controlled?
Knowledgebase Article
}
Knowledgebase Article
OpCache was introduced from PHP7 and helps make PHP sites faster.
To understand what OpCache is, it’s necessary to also understand that PHP scripts are uncompiled, human readable code. This is part of what makes PHP a useful coding language as you don’t have to “compile” your code to run it, as you do in many other languages.
If OpCache is turned off, each time the code runs, it is compiled into “opcode” - which is executable machine code that the server can understand how to process (essentially a series of 1s and 0s).
With OpCache enabled, that “opcode” is stored on disk, so the next time the code runs, it doesn’t have to compile it again - effectively making the code run faster as there is less work to do.
The cache for that file will automatically be purged whenever that file is modified.
Applications can also store other data in OpCache, such as objects. As this is not a cache of the raw PHP code, we are unable to know when this needs to be purged. As such, OpCache can be reset programatically by your applications as and when required.
Many applications do this natively, or have a plugin or extension which is capable of doing this when required. Some hosts automatically reset OpCache whenever the web service restarts.
A web service restart happens, for example, whenever a new domain is added to or removed from the server. This could be many hundred times per hour on a busy server. If websites are relying heavily on OpCache, it is counter-productive to reset it unnecessarily, and as such to ensure customer OpCache is always warm, we run PHP in detached mode.
This allows us to avoid resetting your OpCache with every web service restart, so your cache can remain fully primed and any OpCache resets can simply be handled at an application level.
If your application does not automatically clear OpCache when required or after an update, a tool in our cPanel exists so that you can manually purge the cache at the click of a button. Just click the Clear Opcache button to purge your entire OpCache.
If your site is performing slowly, take a look at your PHP Extensions in cPanel and make sure that OpCache is enabled.
Powered by WHMCompleteSolution