User Tools

Site Tools


PHP OPcode Cache Guide


Each time when PHP script executes on the server it goes through the following stages: tokenizing, parsing, compilation, and interpretation. PHP opcode caching allows skipping the first 3 stages by storing pre-compiled scripts in shared memory and reusing them. This significantly increases the performance of running PHP scripts. 

It is important to know that opcode cache works only with certain types of PHP handlers. Among those available in cPanel handlers it works with: * DSO (mod_php) * fcgid * PHP-FPM

Opcode cache DOES NOT work with following handlers: * SUPHP * CGI

There were historically several implementations of opcode cache available for cPanel: * APC * APCu * eAccelerator * xCache * Zend OPcache

In latest PHP versions only Zend OPcache and APCu are supported.

Zend OPcache

Zend OPcache caches only opcode. 

How to check if Zend OPcache is installed or not

Run the command:

php -v

If EasyApache3 is used, the output will show you for sure whether OPcache is used. For example:

# php -v
PHP 5.6.36 (cli) (built: May 29 2018 01:54:47)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with the ionCube PHP Loader (enabled) + Intrusion Protection from
(unconfigured) v6.1.0 (), Copyright (c) 2002-2017, by ionCube Ltd.with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

However, if EasyApache 4 is being used and several PHP versions are installed, 'php -v' command displays only default PHP version. You could run the following command to see installed opcache modules:

yum list -q installed ea-php*opcache

If the result is empty then no opcache modules are installed.

Installation and configuration of Zend OPcache on EasyApache 3

EasyApache 3 requires rebuilding to add/remove modules. Run:


Then follow the menu, enter "Customize Profile" section, find "Zend Opcode caching extension" entry in Exhaustive Options List, select it, then save configuration and start rebuilding process.

Installation and configuration of Zend OPcache on EasyApache 4

EasyApache 4 moved to RPM-based model and does not require entire rebuilding each time when you need add or remove a module. It is managed by running yum command. For example, if you need to install opcache module for PHP 7.0, run:

yum install -y -q ea-php70-php-opcache

In WHM interface opcache module could be added from (Home » Software » EasyApache 4). Click on "Customize" button, enable opcache module on "PHP extensions" sections, and apply the changes.

Zend OPcache configuration

In EasyApache 3 all PHP settings including opcache parameters are located in one configuration file. In EasyApache 4 each module has its own configuration file for each installed PHP version. By running 'php –ini' you can find out the location of that file. For example, in EasyApache 4 and PHP 5.6 it would be: /opt/cpanel/ea-php56/root/etc/php.d/opcache.ini 
Here's default settings:

# grep opcache /opt/cpanel/ea-php56/root/etc/php.d/opcache.ini

You can see that by default OPcache is enabled but disabled for CLI version of PHP. You could also notice that validate_permission is turned on which is important in shared environments. 
Detailed description for each parameter is available at: *

To view the current settings you can also run:

php -i|grep ^opcache

Or for non-default PHP version:

scl enable ea-php70 'php -i|grep ^opcache'


This is a useful tool for monitoring OPcache performance. The site of the project: *

Just copy the file index.php (of course with renaming it to, for instance, opcache.php) to site's root directory and open in the browser.


Alternative PHP Cache which caches both opcode and user data. It used to work up to PHP 5.4 but now is no longer maintained. Zend OPCache essentially replaced its functionality (except data cache).

Installation on EasyApache 3

Performed via PECL, for example

pecl install channel://



APC User Cache. Does not cache actual opcode like Zend OPcache and APC. Instead, it caches user data which allows it to run alongside Zend OPcache. 
Source code of the project is located at: *

Installation on EasyApache 3

Also performed via PECL, for example

pecl install channel://

Installation on EasyApache 4

You can install APCu for particular PHP version in EA4 using following example

/opt/cpanel/ea-php70/root/usr/bin/pecl install channel://

APCu version 5.X requires PHP 7.0+ to run while version 4.X could be installed on PHP 5.5 and 5.6.

To check APCu module run:

#scl enable ea-php70 'php -m|grep apc'


Using APCu

Since APCu caches only user data, its usage should be implemented in code (instead of opcode caching which is ready to go after installation). There are plugins for CMS like Wordpress which allow easily to get apcu running. For example, APCu Object Cache Backend plugin. Install it from available plugins in Wordpress panel. Then move php script inside document root:

mv wp-content/plugins/apcu/object-cache.php wp-content/object-cache.php

Monitoring APCu

There're several well-known scripts which use function apcu_cache_info() to monitor cache usage. An example of such tool is described at: *

Download the php script in site's document root. Then open it in a browser and you could see the current cache usage.

developmental/php-opcode-caching-guide.txt · Last modified: 2018/07/13 19:38 by Daniel P.