2.2.4. OPcache

OPcache is designed to cache compiled PHP scripts bytecode in RAM. Its use allows to some extent speed up the work of site scripts and reduce the load they create on the web server. OPcache can be used on any site, no special site support is required.

Important points:

  • Unfortunately, it is impossible to determine in advance the amount of memory for OPcache that the site will need. You can find out a specific figure only experimentally, by connecting the service and studying the collected statistics... Most sites rarely need more than 32MB.
  • Several ordered volumes are summed up.
  • On businesshosting OPcache does not need to be ordered. It is available free of charge within the allocated amount of RAM.
  1. Open the section "Hosting".
  2. In the block "Extra services" click "OPcache":
  3. In the drop-down list, select the required amount of memory and click "To order" (if the system informs about the presence of an unpaid order, in the text of this notification click "undo"and then repeat the order):
  4. If this is the first time ordering the service, skip this step to use free 7-day trial period... Otherwise, pay automatically generated invoice any of available ways and wait for the payment to be credited.
  5. Wait approximately 30 minutes for the service to activate.
  6. Enable OPcache for the sites you want.

Important points:

  • The total amount of OPcache memory distributed between sites cannot exceed the ordered one. For example, if you order 32 MB and allocate them to one site, then you will not be able to allocate memory to the second site - you will need to either reduce the volume allocated to the first site, or order additional memory.
  • To use OPcache, the site settings must be set PHP version not lower than 5.5.
  • If there is not enough memory allocated for OPcache on the site, there may be error 503... It's not about filling the cache storage by 100%, but about setting too little OPcache allocated memory for the site.
  • OPcache Preloading is not supported due to insecure configuration and the need to update memory-loaded scripts that can only be updated by restarting the PHP service.
  1. Openup PHP settings.
  2. Check the box next to "OPcache caching " and in the field "Memory for OPcache" specify the amount of memory allocated to the site:

Parameter "Change check frequency" (opcache.revalidate_freq) defaults to zero. This means that with each request it will check whether the script has changed and whether it can still be taken from the cache or needs to be called again. It makes sense to use a value greater than zero if the site receives a large number of requests and its files are not being edited. This will give some performance gain at the expense of reducing the number of disk operations.

Important points:

  • Fully filled Opcache will not create errors in the site, but it may be one of the signs that you need to increase the allocated memory for caching.
  • When the storage is 100% full, unpopular and old data will be overwritten by more popular ones, there is no need to worry about the efficiency of caching.

To view statistics of OPcache usage in the section "Hosting" in the block "Extra services" click "OPcache statistics":

In the OPcache statistics, you can find the following information:

  • The current status of OPcache.
  • The version of the module being used.
  • List of sites for which OPcache memory is allocated.
  • Percentage pie chart "Percentage of total volume", which displays:
    • Percent busy memory.
    • Percent free memory.
    • Percent lost (Wasted) memory. Lost memory — this is memory, which is already occupied by outdated, irrelevant data. It appears due to changes in scripts or the inability to use the current data for them. Such memory is cleared automatically when a certain fraction of the maximum of the total memory is reached, so manual clearing is not required. This approach provides faster OPcache functionality.
  • Percentage pie chart "Percentage of all requests", which displays:
    • Hits — statistics of requests to scripts that were in the cache, and the result was provided without executing the source code.
    • Misses — statistics of requests to scripts that not were in the cache and were executed.
  • Configuration — a list of OPcache options. All options can be found in documentation.

Example statistics:

There are several ways to clear the OPcache cache:

  • Through the control panel — use the button "Clear cache" opposite the desired site in the section statistics.
  • Across Telegrambot:
    • For a specific site — in the bot menu, select "Hosting → Sites → desired site → Clear OPcache cache".
    • For all sites of the hosting account at once — in the bot menu, select "Hosting → Hosting account → your hosting account → Clear cache → Clear OPcache cache".