CityHost.UA
Help and support

Connecting OPcache

OPcache improves the performance and loading speed of PHP scripts by storing the compiled bytecode in RAM, thus saving the web server from having to load and parse the scripts with each request.

To connect the service, you need to go to your control panel and find the necessary hosting account, click Management -Add service - OPcache - Order.

 

16 megabytes of RAM for the OPcache service is allocated free of charge. Unfortunately, it is not possible to find out in advance how much memory needs to be allocated specifically for your site, since it is individual for each site, and the exact numbers can only be found out experimentally (see Checking OPcache operation)

After clicking on "Order", a window will open in which you need to select the amount of memory allocated for OPcache (for example, 16 MB), then confirm the action by pressing the "Order" button again.

 

After the Opcache service has been ordered, you need to connect it to a specific site. To do this, go to the tab Sites - PHP Options - Edit .

 

In the window that opens, find the Caching OPcache option and set it to Enabled, below we specify how much memory will be allocated for this site. If you previously ordered 16 MB, then by entering the value 16 in this field, all 16 megabytes will be used by one site.

 

Example: if there are several sites, let's say 2 of them, and you purchased 128 MB of memory, you can allocate 64 MB to each site, or 32 MB to one site (if this is a small site), and 96 to the other (if it is a slightly larger site).

After clicking Save, the settings are complete.

 

Checking the operation of OPcache

 

To check the operation and use of OPcache memory, you need to create a PHP file with an arbitrary name, for example info.php, in the root directory of the site to which the service is connected, and write the following code inside this file:

 

<?php
phpinfo();
?>

 

then save the file and open it in the browser by entering the domain of the site and the name of the PHP file in the address bar, for example domain.com/info.php You can edit files on the hosting both with the help of a file manager and through an FTP connection.

 

After opening this file, we find the Zend OPcache section in it, where we are most interested in the lines highlighted in yellow.

Cache hits — the number of calls to scripts that are in the cache. We want this metric to always be higher than the Cache misses metric.

 

Cache misses — the number of calls to scripts that are not in the cache and were executed bypassing OPcache. The less the better.

 

Used memory — the amount of RAM used by the site when working with OPcache. This value appears in bytes, read the first 2 digits (if very rough). In the example above, the site has 128 MB allocated, of which it consumes approximately 94 MB and 39 MB is unused. Experimentally, it was found that a 128 MB package is required for a specific site to work with OPcache.

 

Free memory — Free memory that can be allocated for another site, or kept in reserve for the main one.

 

For more in-depth analysis and viewing of OPcache statistics, you can create another PHP file, for example opcacheinfo.php, and write the following code inside this file:

 

<?php
opcache_get_status();
?>