Brother Niao said in his blog that there are several tips to improve the performance of PHP7. The first one is to enable opcache:
Remember Enable Zend Opcache, because PHP7 is faster even without Opcache than PHP-5.6 with Opcache enabled.
So during the previous testing period, some people did not enable Opcache.
So what is Opcache?
The predecessor of Opcache is Optimizer
, which is a closed-source but free-to-use PHP optimization acceleration component developed by Zend, the official company of PHP. Optimizer caches the script file Opcode
generated by precompiling the PHP code in the shared memory for repeated use in the future, thus avoiding the time consumption of reading the code from the disk and compiling it again. At the same time, it also applies some code optimization modes to make the code execute faster. Thereby speeding up the execution of PHP.
The normal execution process of PHP is as follows
##request request (nginx, apache, cli, etc.)-->Zend engine reads the .php file-->Scans its dictionary and expressions-->Parses the file-->Creates The executed computer code (called Opcode)-->Finally execute Opcode--> response returns
Each time the PHP script is requested, the above steps will be executed. If the PHP source code does not If the Opcode changes, then the Opcode will not change. Obviously there is no need to regenerate the Opcode every time. Combined with the ubiquitous caching mechanism in the Web, we can cache the Opcode. Wouldn’t it be faster to directly access the cached Opcode in the future? After enabling the Opcode cache The flow chart is as follows:
The purpose of Opcode cache is to avoid repeated compilation and reduce CPU and memory overhead.
The following describes the installation of Opcache
Installation:
1 2 3 |
|
Configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
View phpinfo:
The above is the detailed content of Do you know how to enable opcache in PHP7 to improve performance?. For more information, please follow other related articles on the PHP Chinese website!