Php accelerator (XCache), php implements LAMP-php Tutorial in the form of modules

Source: Internet
Author: User
Tags php introduction zts
Php accelerator (XCache), php implements LAMP in the form of modules PHP introduction

PHP is a general-purpose server-side scripting language. it is mainly used for web development to implement dynamic web pages. it is also one of the earliest server-side scripting languages used to embed scripts into HTML source code documents. At the same time, php also provides a command line interface, so it can also be used as an independent shell on most systems.


PHP Zend Engine

Zend Engine is an open-source PHP script language interpreter developed by C language and highly optimized. it can be used as a backend module of PHP. Zend Engine provides memory and resource management functions and other standard services for PHP. its high performance, reliability, and scalability play an important role in promoting PHP to become a popular language.

The emergence of Zend Engine divides the PHP code processing process into two phases: first, it analyzes the PHP code and converts it to a binary format called Zend opcode (similar to Java bytecode ), and store it in the memory. The second stage is to use Zend Engine to execute the converted Opcode.


PHP Opcode

Opcode is an intermediate language after PHP script compilation, like ByteCode of Java or MSL of. NET. PHP script code execution generally goes through the following four steps (specifically, it should be the PHP language engine Zend ):

1. Scanning (Lexing)-convert PHP code into a language segment (Tokens)

2. Parsing (analysis)-converts Tokens into simple and meaningful expressions.

3. Compilation (compile)-compile the expression into Opocdes

4. Execution: execute Opcodes one by one each time to implement the PHP script function.


Php accelerator

The compiling result of a PHP process (corresponding to a request) cannot be used by the second PHP process (opcode cannot be shared). This makes every request to a dynamic page need to be scanned and analyzed, compile and execute the same request. The four steps are required. Then there are various PHP accelerators.

The php accelerator is a special extension mechanism based on PHP, such as opcode cache extension. you can also cache opcode in the php shared memory, so that the compilation phase can be skipped during subsequent repeated execution of the same piece of code to improve performance. It can also be seen that these accelerators do not really increase the opcode speed, but simply analyze the opcode and rearrange them for fast execution. Common php accelerators include: APC (Alternative PHP Cache), eAccelerator, XCache, NuSphere PhpExpress, Zend Optimizer and Zend Guard Loader ........ XCache is fast and stable. it has been strictly tested and used in a large number of production environments. Address: http://xcache.lighttpd.net/


XCache installation

The installation environment is xcache-3.1.0.tar.bz2.

1. Installation

[Root @ www ~] # Lltotal 20532 ......-rw-r --. 1 root 146444 Jul 5 xcache-3.1.0.tar.bz2 ...... [root @ www ~] # Tar xf xcache-3.1.0.tar.bz2 [root @ www ~] # Cd xcache-3.1.0 [root @ www xcache-3.1.0] #/usr/local/php-5.4/bin/phpize # prepare a module for compiling php support # third-party module (integrated with the current php) padding ING for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525

/Usr/local/php-5.4/bin/phpize this step must be executed here, after the execution is complete, the configure script file will be available under the Directory of the installation package


[root@www xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php-5.4/bin/php-config.......[root@www xcache-3.1.0]# make && make install

At the end of installation, the following lines will appear:

Installing shared extensions:/usr/local/php-5.4/lib/php/extensions/no-debug-non-zts-20100525


2. edit php. ini and integrate php and xcache.

First, import the sample configuration provided by xcache to php. ini.

[root@www xcache-3.1.0]# mkdir /etc/php.d[root@www xcache-3.1.0]# cp xcache.ini /etc/php.d

Note: The xcache. ini file is in the xcache source code directory.


Next, edit/etc/php. d/xcache. ini, find the line starting with zend_extension, and change it to the following line:

extension = /usr/local/php-5.4/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

Note: If the php. ini file contains multiple zend_extension command lines, make sure that the new lines are ranked first.

Parameters in xcache. ini:

; To enable: xcache. size = 64 M etc (any size> 0) and your system mmap allowsxcache. size = 60 M # memory size used for caching; set to cpu count (cat/proc/cpuinfo | grep-c processor) xcache. count = 1 # set it to the number of cpu cores; just a hash hints, you can always store count (items)> slotsxcache. slots = 8 K; ttl of the cache item, 0 = foreverxcache. ttl = 0; interval of gc scanning expired items, 0 = no scan, other values is in secondsxcache. gc_interval = 0

Load services in the center after completion

[root@www xcache-3.1.0]# service php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done


Access the configuration page:

Loaded xcache


Use the AB command to perform a pressure test on the php Server. the command format is as follows:

AB-n num-c num url

-N # total number of requests

-C # number of concurrent requests


Disable the cache function first:

[root@www php.d]# mv xcache.ini xcache.ini.bak[root@www php.d]# service php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done

Start test:

[root@www ~]# ab -n 200 -c 5 http://admin.xiaoxiao.com/index.phpThis is ApacheBench, Version 2.3 <$Revision: 1554214 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking admin.xiaoxiao.com (be patient)Completed 100 requestsCompleted 200 requestsFinished 200 requests


Start xcache:

[root@www php.d]# mv xcache.ini.bak xcache.ini[root@www php.d]# service php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done[root@www ~]# ab -n 500 -c 20 http://admin.xiaoxiao.com/index.php.........

The speed is more than twice, and the effect is quite obvious ~~

.................... ^

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.