opcache principle
1. What Opcache that?
Opcache by a PHP script parsed precompiled bytecode (Operate Code) stored in shared memory each time to avoid the overhead of loading and parsing PHP scripts, parsers can be directly read from the shared memory is cached word section code (Operate code), which greatly improve the efficiency of PHP.
2. What is the Operate Code?
After the completion of the analysis of the script interpreter code, which generates the intermediate code can be put directly run, also known as the opcode (Operate Code, opcode). Opcode cache is to head to avoid duplication of compilation, reducing CPU and memory overhead. If the performance bottleneck of dynamic content is not the CPU and memory, but in I / O operations, such as database queries to bring the disk I / O overhead, then the opcode cache performance improvement is very limited. But since opcode cache can bring reduce CPU and memory overhead, which is always a good thing. Modern operating code register (Optimizer +, APC2.0 +, other) to use shared memory for storage, and may be executed directly from a file, rather than before execution "deserialization" code. This will bring significant performance boost, usually in particular reducing the overall server memory consumption of high flow and high concurrency, and few drawbacks.
3. Why use Opcode cache?
This was from the life cycle of PHP code, PHP script request will go through five steps, as shown below:
Zend engine must be read from the file system file, scan its dictionary and expressions, parse documents, create computer code to be executed (called Opcode), the last execution Opcode. Each request will be executed PHP script steps above again, if the PHP source code does not change, then Opcode will not change, obviously it is not necessary every time the heavy-line build Opcode, combined with the ubiquitous Web caching mechanism, we can put down Opcode cache , directly after the access to the cache is faster Opcode it not, then the flowchart Opcode caching enabled as follows:
Thus after use the cache Operate Code, PHP code opcode executed directly after the direct access, three intermediate steps will be omitted thus substantially increase the efficiency of PHP code
Third, the installation and use of Opcache
1, the installation
1 2 3 4 5 6 7 8 9 10 |
|
2, using
1 2 3 |
|
3, Configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|