Introduction to PHP Cache acceleration
1. Operation code Introduction and caching principle When a client requests a PHP program, the server's PHP engine parses the PHP program and compiles it into a specific opcode file (Operate code, OpCode) The file is a binary representation of the PHP code after it is executed. By default, this compiled opcode file is discarded by the PHP engine after it is executed. The principle of opcode caching (Opcode cache) is that the compiled opcode is saved and Iceland is shared in memory so that it can be reused the next time the PHP page is called, avoiding duplicate compilation of the same code. Saves the PHP engine from repeating compile time, reduces server load, and reduces CPU and memory overhead. Accelerated performance up to 2-10 times 2.php cache acceleration Software Introduction in order to improve the PHP engine high concurrent access and execution speed, resulting in a series of PHP caching and Acceleration software. The purpose of these software settings is to cache the PHP engine resolution of the opcode file, so that in a specified time when the same PHP program request access, no longer need to repeat the resolution compiled, but directly invoke the cache of the PHP opcode file, so as to improve the dynamic Web services processing speed, This improves the user's overall experience of accessing the corporate Web site. 3.Apache Environment PHP Caching Accelerator principle in lamp environment, Apache service is using libphp5.so response to process PHP request, the whole process is as follows: 1, Apache receives the client's PHP program request and filters it according to the rules. 2, Apache PHP program request passed to the PHP processing module libphp5.so 3, PHP engine positioning disk PHP file, and loaded into memory to resolve 4, PHP processing module libphp5.so PHP source code compiled into opcode 5, The PHP processing module libphp5.so executes the opcode, then caches the opcode 6, Apache receives the client new PHP program request, the PHP engine directly reads the cache execution opcode file, and returns the result. In this task, there is no 4th step of the compilation resolution, thereby enhancing the PHP compiler resolution efficiency LNMP environment PHP Cache accelerator principles in the LNMP environment, Instead of using the libphp5.so module, the PHP engine starts the standalone fcgi, the PHP-FPM process, which listens to the PHP request from Nginx and gives the PHP engine an analytic process, the entire execution process is as follows: 1) nginx receive client's PHP program Access request. 2) Nginx the ph according to the filter rules such as extension nameP Program request pass to parse PHP fcgi process (PHP-FPM) 3) PHP FPM process calls PHP parser to read the PHP file on the site disk and load into memory. 4 PHP parser compiles the PHP program into a opcode file, and then caches the opcode. 5 The PHP fpm engine executes the opcode tree, returns the data to the Nginx, and returns the client. 6 Nginx receive the Client new PHP program request, the PHP FPM engine will read directly in the cache opcode execution, will return the result, this process does not need the 4th step operation, thus enhanced the PHP compilation analytic efficiency.
PHP cache accelerator software types and options recommended PHP cache Accelerator software Common types are XCache, Eaccelerator, APC (altemative PHP cache), Zendopache and so on. The recommendations are based on the business needs and the stress test results prior to selection, or on the basis of individual experience preferences. However, recommended preferred XCache, followed by Eaccelarator, if you want to use the new, you can choose Zendopcache. Note: APC is called altemative PHP cache, but also a good PHP caching accelerator software. You can view related documentation: http://pecl.php.net/packages.php and Http://pecl.php.net/package/APC preferred XCache for the following reasons: 1. Tested XCache more efficient, faster 2. The XCache software development community is more active. 3. Support for a better version of PHP, such as PHP5.5, PHP5.6 Eaccelerator for the following reasons: 1, installation and configuration parameters simpler, accelerated effect is also good 2, more documents, but the official update of the software is slow, the community is not active 3, The reason for selecting Zendopcache for programs that are only suitable for PHP version 5.4 is as follows: 1. PHP is the official development of the next generation of cache accelerator software, the future development potential will be very good, PHP5.5 Previous versions can be installed through the Zendopcode Software plug-in extensions, from the PHP5.5 version has been integrated into the PHP software, compile-time only need to specify a parameter, such as: –enable-opcache 2, Zendopcache may be the future cache acceleration preferred, now the stability has yet to be tested, the small scale of the PHP5 before the version can be installed through plug-in installation, PHP5 version of the above can directly specify the parameters of the compiler to use, if you can hot hand zendopcache the various unknown problems , you can try using.
Install the PHP accelerator plugin1. Environmental preparedness
[Root@web02 ~]# Cat/etc/redhat-release
CentOS Release 6.7 (Final)
[Root@web02 ~]# Uname-r
2.6.32-573.el6.x86_64
[Root@web02 ~]# Uname-m
x86_64
2. Software version Information
Nginx Version Information
[Root@web02 application]#/application/nginx/sbin/nginx-v
Nginx version:nginx/1.6.3
Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNI Support Enabled
Configure arguments:--prefix=/application/nginx-1.6.3/--user=www--group=www--with-http_ssl_module--with-http_ Stub_status_module
PHP Version Information
[Root@web02 application]#/application/php/bin/php-v
PHP 5.5.32 (CLI) (Built:may 24 2016 13:55:46)
Copyright (c) 1997-2015 the PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
MySQL version information
[Root@db01 ~]# Mysql-v
MySQL Ver 14.14 distrib 5.5.49, for linux2.6 (x86_64) using ReadLine 5.1
The process of configuring environment variable Lc_all is as follows: