X

Setup and Optimize Zend OpCache

Zend Opcache

Zend OPCache:

Zend OpCache is a caching engine that comes with PHP by default in later releases (PHP 5.5 and above).  It is a caching engine that stores precompiled php code in memory which ultimately results in performance increase as the code does not have to be fully recompiled on each new request.  The degree to which these performance improvements are noticeable depends on how busy your site is.  The busier your site, the more noticeable.

To utilize opcache, you need to have a PHP installation, if you do not please see Compiling PHP From Source

Install Instructions:

If you have a php release before 5.5 you install Opcache with the PECL:

pecl install opcache

Then add the following line to php.ini

extension="opcache.so"

If you are not sure where your php.ini to the following to locate it:

# php -i|grep 'Loaded Configuration'
Loaded Configuration File => /etc/php.ini

Finally restart the web server to load it.

Performance Tuning:

opcache.revalidate_freq – This is how often to check php scripts timestamps for updates. Setting this to 0 will result on opcache checking every time for updates on the script.

opcache.validate_timestamps – If this is enabled, this will check php scripts based on the revalidate_freq to check for updates.  If this is disabled it  wont check for updates at all.

opcache.max_accelerated_files –  The number of scripts that can be in the hash table. There should be less scripts than what this number is set to. To find the total amount of php files do the following:

find /path/to/web/dir -type f -name "*.php"|wc -l

opcache.memory_consumption – Size of the shared memory storage used by the cache in MB.  This is how much memory the cache is allowed to consume.

opcache.interned_strings_buffer – The amount of memory used to store interned strings in MB. This is basically compression for php, If you use the same strings multiple places it stores it once and then uses pointers when its used other places.

opcache.fast_shutdown – Allows for faster shutdown

Suggested values:

You can place the following in your php.ini and restart the webserver to load the performance settings:

opcache.revalidate_freq=0
opcache.validate_timestamps=0 (if disabled it wont check at all)
opcache.max_accelerated_files= (use the find example above)
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.fast_shutdown=1

You can find more explanation here

 

 

LinuxAdmin.io
2.8 8 votes
Article Rating
LinuxAdmin.io:
Related Post