Zend OPcache speeds up the execution of PHP codes. How? We know that PHP is an interpreted language where the instructions are written in a script and needs a process to parse/interpret and execute it. Zend OPcache removes the parse/interpret part by compiling the script to directly executed it by the target machine which makes the execution of your PHP application more faster. This article will show how to setup Zend OPcache on CentOS 7.
The following procedures are tested on my Linode server running Centos 7 64-bit Linux distribution.
- Install the PHP Zend OPcache:
yum install php-pecl-zendopcache
- Configure Zend OPcache optimized for your PHP application. Edit opcache.ini:
... and change the following to:
opcache.revalidate_freq=0 opcache.validate_timestamps=0 opcache.max_accelerated_files=20000 opcache.memory_consumption=128 opcache.interned_strings_buffer=16 opcache.fast_shutdown=1
Comment out the line "opcache.validate_timestamps=0" in your development environment.
To get the "opcache.max_accelerated_files" you may use this:
find . -type f -print | grep php | wc -l
Since I'm using Dupal, I added these:
find . -type f -print | grep module | wc -l find . -type f -print | grep inc | wc -l
- If you don't want to apply Zend OPcache to your development site you may add its path at opcache-default.blacklist:
- Restart your Apache:
service httpd restart
- You can download the web UI for Zend OPcache status at https://raw.github.com/rlerdorf/opcache-status/master/opcache.php. Make sure that you protect this web UI from prying eyes.