PHP Service Cache Acceleration--xcache installation and Configuration

Source: Internet
Author: User
Tags imagemagick memcached php memcached phpinfo administrator password

Introduction to 1.PHP Cache accelerator

(1) Introduction of operation code and principle of accelerator

When a client requests a PHP program, the server's PHP engine parses the PHP program and compiles it into a specific opcode (Operate code, abbreviated to opcode file), which is a binary representation of the PHP code after it executes. By default, this compiled opcode file is discarded by the PHP engine after it is executed. The operation code cache (opcode cache) is the principle of the post-compilation code error down, and put into the shared memory, in order to reuse it the next time the PHP page, it avoids the same code repeated compilation, Save the PHP engine repeatedly compile time, reduce the server load, Colleagues reduce the overhead of CPU and memory.

(2) Introduction of PHP Cache accelerator software

In order to improve the high concurrent access and execution speed of PHP engine, a series of PHP cache acceleration software is produced. The purpose of these software design is to cache the previously mentioned PHP engine parsed opcode file, in order to have the same PHP program request access within a specified time, do not need to re-parse the compilation, but directly invoke the PHP opcode file in the cache, thus improving the processing speed of dynamic Web services, This improves the overall experience of users accessing corporate websites.

(3) LNMP environment PHP Cache Accelerator principle Detailed.

In the LNMP environment, the PHP engine uses a separate fcgi (that is, the PHP-FPM process, Apache is the libphp.so module), he listens to the PHP program request from Nginx, and to the PHP engine processing, the entire execution process is probably as follows.

1) nginx receive client's PHP program Access request

2) Nginx According to the extension name and other filtering rules to pass the PHP program request to parse PHP fcgi process.

3) The PHP fpm process calls the PHP parser to read the PHP file on the site disk and load it into memory.

4) The PHP parser compiles the PHP program into a opcode file and then caches the opcode.

5) PHP fpm engine executes opcode tree, return data to Nginx, and return to client

6) Nginx receives the client new PHP program request, the PHP engine will directly read the opcode in the cache and execute, return the result. No fourth is needed to improve the efficiency of PHP compilation parsing.

2.PHP Cache Accelerator Installation Environment preparation

PHP cache Acceleration Software A lot of kinds, such as Eaccelerator,apc,xcache,zendopcache. Here we choose the time to XCache, because the xcache is more efficient, the community is more active, support for the 5.6 version of PHP. Zendopcache may be the first choice for the future, the official accelerator software, but not many people are using it at the moment.

Before installing the XCache Accelerator, we need to install the LNMP complete environment, in front of which we have already installed the LNMP service environment. The installed version is as follows

Project Version
Linux CentOS Release 6.5 (Final)
Nginx nginx-1.12.2
Mysql 5.6.31 64bit
Php php5.6.31
3. Installing the XCache Cache accelerator

Because we use PHP version of 5.6, through the XCache official website can understand the need to use 3.20 version to support PHP5.6, can be downloaded to the official website. http://xcache.lighttpd.net/. Install the steps for decompression, compile the installation, the specific command is as follows:

TAR-XF xcache-3.2.0.tar.gzcd xcache-3.2.0.tar.gz/usr/local/php/bin/phpize #必不可少的一步./configure--enable-xcache--wi Th-php-config=/usr/local/php/bin/php-config Makemake Install

In the process of compiling the installation, if you are prompted for a missing class library file, you can install it with Yum and the xcache.so file will be generated in the PHP directory after successful installation.

4. Install the database cache and other PHP extension plugins (optional)

(1) Install php memcached extension plugin

Memcached is an open source, supporting high performance, high concurrency, and distributed memory caching service software. In traditional scenarios, most Web applications save data to the database, and the WWW server reads the data and displays it in the browser. However, with the increase of data volume, the concentration of access, there will be an increase in the burden of RDBMS, database response is slow, web site opening delay problem. The main purpose of using memcached is to reduce the number of data accesses by caching the query results of the database in its own memory, so as to reduce the direct high concurrent access of the front-end business to the database, thus improving the concurrent access ability of the large-scale Web site cluster dynamic service.

Memcached we will be in the next post to do a detailed introduction, here we only install Memcachedd client software--memcache, in order to build a good memcached after the service can be used. The steps to install are as follows:

TAR-XF memcache-2.2.7.tgz/usr/local/php/bin/phpize #必不可少的一步./configure--enable-memcache--with-php-config=/usr/l Ocal/php/bin/php-config Makemake Install

After successful installation, memcache.so files are generated in the PHP directory.

(2) Installing ImageMagick image software

ImageMagick is a powerful, stable and free toolkit and development package that can be used to read and write and process 89 basic format amount picture files. With ImageMagick, you can dynamically generate images based on the needs of your Web application, and you can change the size, rotation, sharpening, and so on for one (or a group of) images, and save the results of the operation in the same format or other format. The steps to install are as follows:

TAR-XF imagemagick-6.7.9-9.tar.xzcd Imagemagick-6.7.9-9./configuremakemake Install

PS: This software is not the extension of PHP, so it is not generated. So, the Imagick plugin that is installed later will generate the corresponding. so file.

(3) Imagick plug-in work needs ImageMagick software support, so you need to install ImageMagick software, otherwise the plug-in will not install. The installation method is as follows:

TAR-XF imagick-3.4.3.tgz #之前打算安装2.3 version, error, later to the official website to find a newer version of the CD imagick-3.4.3/usr/local/php/bin/phpize #必须的 Step./configure--with-php-config=/usr/local/php/bin/php-config make do install

After successful installation, imagick.so files are generated in the PHP directory.

5. Configuring the PHP acceleration and caching-related extension plugin module

(1) Configure the Memcache/imagick module to take effect

To make the module you just installed work, we need to edit the PHP configuration file php.ini. Execute Vim/usr/local/php/lib/php.ini, look for "Extension_dir", and then change to "

Extension_dir = "/usr/local/php5.6.31/lib/php/extensions/no-debug-non-zts-20131226/", next to the end of the file, add "

Extension = memcache.so Extension = imagick.so ", the section of the configuration file is as follows:

Verify the php.ini file, if no problem, restart the PHP-FPM service, view the Phpinfo () page to check the corresponding plugin

/usr/local/php/sbin/php-fpm-t #出现successful字样才行pkill php-fpm #重启php-fpm service/USR/LOCAL/PHP/SBIN/PHP-FPM

(2) Configure XCache plug-in acceleration

In the Software decompression directory/root/xcache-3.2.0, there is a Xcache.ini configuration file, that is, xcache configuration file. After we have adjusted the parameters according to this configuration file, we copy to the last part of the php.ini file, see the Notes

[xcache-common]extension = xcache.so        ; Loading xcache.so[ xcache.admin]xcache.admin.enable_auth = on        ; Open certification xcache.admin.user =  "PCM"                                       ; This custom xcache.admin.pass =  " 62b6d07a02edc7d58cb622def452e81b "        ; This MD5 is generated in the back to fill in [XCache] xcache.shm_scheme =         "Mmap"     ; Set XCache How to allocate shared memory from the system xcache.size  =                256M    ; set the size value of the XCache cache xcache.count =                  1xcache.slots =                 8Kxcache.ttl   =                  86400        ; set the lifetime TTL of the cache object, 0 to never expire xcache.gc_interval =            3600xcache.var_size  =             64mxcache.var_count =              1xcache.var_slots =            8kxcache.var_ ttl   =              0xcache.var_maxttl   =          0xcache.var_ gc_interval =     300xcache.var_namespace_mode =    0xcache.var_namespace =          "" xcache.readonly_protection = offxcache.mmap_path =      "/dev/zero" xcache.coredump_directory =    "" xcache.coredump_type =          0xcache.disable_on_crash =     offxcache.experimental =        offxcache.cacher =                Onxcache.stat    =                onxcache.optimizer =           off[ xcache.coverager]xcache.coverager =            Offxcache.coverager_autostart =  onxcache.coveragedump_directory =  "" 

After adding, we check the configuration of XCache acceleration, and we can see that the configuration of XCache is already referenced.

Then we restart the PHP-FPM process, to the phpinfo () page to check whether the effect

/usr/local/php/sbin/php-fpm-t #出现successful字样才行pkill php-fpm #重启php-fpm service/USR/LOCAL/PHP/SBIN/PHP-FPM

Ps:md5 How to generate an administrator password

[[email protected] ~]# echo-n "pcm123456" |md5sum 62b6d07a02edc7d58cb622def452e81b-Put the key in the php.ini file

(3) Configure the Web interface to view XCache cache acceleration Information

In the XCache software extract directory under the management XCache site Directory, we copy it to the blog virtual host. Operation is as follows

Cp-a/root/xcache-3.2.0/htdocs//usr/local/nginx/html/blog/xadmin chown-r nginx:nginx/usr/local/nginx/html/blog/ Xadmin/pkill php-fpm #重启php-fpm service/USR/LOCAL/PHP/SBIN/PHP-FPM

Browser then open the Xadmin page, enter the account password will appear below the page. http://blog.pcm.com/xadmin/index.php

6.PHP cache acceleration for stress testing

We're all done, and we always have to know how much performance has been improved after these configurations. Below we use the Webbench tool to test, webbench installation and use method can refer to https://www.cnblogs.com/fjping0606/p/5852049.html, the following test results

(1) A cache accelerator is used. Concurrent quantity is 30, test time 30 seconds

At the time of the test, top


(2) without the use of accelerators, the concurrent quantity is 30, the test time is 30 seconds.

The situation of the corresponding top

(3) It can be seen that using the XCache cache accelerator, access to PHP Web page performance increased by about 3 times times.




PHP Service Cache Acceleration--xcache installation and Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.