Brief introduction
Zend Opcache, formerly known as Zend Optimizer + (Zend o+), was renamed Opcache in mid-March 2013. It provides faster PHP execution through opcode caching and optimization. It stores precompiled script files in shared memory for later use, avoiding the time consuming of reading code from disk and compiling it. It also applies some code optimization patterns to make code execution faster.
PHP comes with the Zend Opcache extension after the 5.5 release, but it is not on by default, and the php5.2,5.3,5.4 version is also available, but you need to download the extension yourself.
What is a opcode cache
In-depth understanding of PHP principles opcodes
When the interpreter finishes parsing the script code, it generates intermediate code that can be run directly, also known as the opcode (Operate code,opcode).
The goal of the Opcode cache is to avoid duplication of compilation and reduce CPU and memory overhead. If the performance bottleneck for dynamic content is not CPU and memory, but I/O operations, such as disk I/O overhead from database queries, the performance gains of the opcode cache are very limited.
But since the opcode cache can lead to a reduction in CPU and memory overhead, this is always a good thing--in an environmentally friendly manner, you should also minimize consumption. :D
Modern opcode buffers (optimizer+,apc2.0+, others) are stored using shared memory and can be executed directly from the file without the "deserialization" code before execution. This leads to significant performance acceleration, which typically reduces the overall server's memory consumption and has few drawbacks.
Configuration under Windows
Before the 1,php5.5 version, go to this download extension and put it in the Zend_ext directory.
2. Modify the php.ini configuration
[PHP]
Engine = On
Zend_extension=php_opcache.dll
3, modify the configuration under the official recommendation PHP.ini [Opcache] to get better performance
[Opcache]
opcache.memory_consumption=128
Opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
Opcache.revalidate_freq=60
Opcache.fast_shutdown=1
Opcache.enable_cli=1
Configuration under Linux
1, install the extension (Skip this step above PHP5.5 version)
wget http://pecl.php.net/get/zendopcache-7.0.5.tgz
Tar zxvf zendopcache-7.0.5.tgz
CD zendopcache-7.0.5
/path/to/php/bin/phpize
./configure--with-php-config=/path/to/php/bin/php-config
Make && make install
2, modify PHP.ini
① added under [PHP]
Zend_extension=php_opcache.so
② added under [Opcache]
opcache.memory_consumption=128
Opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
Opcache.revalidate_freq=60
Opcache.fast_shutdown=1
Opcache.enable_cli=1
Reboot Apache or Php-fpm,phpinfo () after configuration is complete see Zend Opcache as Enabled
Or
Php-m|grep Opcache, with display Opcache
Or
Php-v display with Zend Opcache V7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies.
Setting exceptions
Perhaps some content on the server, such as the website that is being debugged, etc., we do not want to opcache it. Then you can use the blacklist to exclude files that require exceptions.
There is a line configuration in the Opcache configuration file, as below,
Opcache.blacklist_filename=/etc/php.d/opcache*.blacklist
This configuration specifies the file that is used to store file name blacklists. It's obvious that a wildcard * is used here to specify a series of files, not just a particular file. You can always enable this line. When you need to exclude certain files, edit the corresponding blacklist file. For example, to edit (or create a new) file for all files under the/srv/www/sites/devsite folder,
Vim/etc/php.d/opcache-devsite.blacklist
Content is,
/srv/www/sites/devsite/*
The wildcard * represents all files under the Devsite folder.
Then restart the PHP-FPM service when it's done.
PHP installation using Zend Opcache extension