Three free PHP accelerators: APC, Eaccelerator, xcache comparison

Source: Internet
Author: User
Tags apc phpinfo zts

Outline:

1. PHP Accelerator principle

2. Installation and configuration of several popular PHP accelerators

3. Comparison


First, the principle of PHP accelerator

PHP Accelerator is a to improve the efficiency of PHP, thereby caching PHP operation code, so that after PHP execution does not have to parse the conversion, you can directly invoke the PHP operation code, so the speed has been improved a lot.

Request and response execution process using mod_php in Apache:

    1. Apache receives the request.

    2. Apache passes the request to mod_php.

    3. mod_php locates the disk file and loads it into memory.

    4. mod_php compiles the source code into the opcode tree.

    5. mod_php executes the opcode tree.

PHP Accelerator is the fourth step, it is the purpose is to prevent PHP every request to compile PHP code repeatedly, because on the high-traffic site, a lot of compilation is often not executed fast? So there is a bottleneck in this is that PHP's repeated compilation affects both the speed and load of the server load, in order to solve this problem, the PHP accelerator was born.

Each request will be repeated execution of the parse-compile-execute, and in practice, the PHP code in the server generally will not change, every time we request to perform some unnecessary operations, which directly affect the performance of PHP, We're going to come here and think about why we don't have to cache? There are already a lot of mature caching mechanism, in the implementation of PHP code should be more than enough, even if our PHP code will change, we can also use a mature algorithm to ensure that code changes after the re-cache, this is not a problem. Yes, that's how the PHP accelerator works:


before caching after caching

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/41/43/wKiom1PR--uhbyuDAAClKSsQkDg313.jpg "title=" 1.png " alt= "wkiom1pr--uhbyudaaclkssqkdg313.jpg"/> 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01 /41/43/wkiol1pr_xhxoftlaagqdaz8hhw197.jpg "title=" 9.png "alt=" Wkiol1pr_xhxoftlaagqdaz8hhw197.jpg "/>


Second, the installation and configuration of several popular PHP accelerators

1. Installation Configuration APC

The APC full name is alternative PHP Cache, which is an extension in PHP pecl.

$ wget http://pecl.php.net/get/apc-3.0.19.tgz$ tar xvzf apc-3.0.19.tgz$ cd apc-3.0.19/apc-3.0.19$/usr/local/php/bin/ phpize$./configure--ENABLE-APC--enable-apc-mmap--with-php-config=/usr/local/php/bin/php-config$ make$ make Install

Next we configure APC, because my pecl extension path has changed, so I have to move the compiled file:

$sudo mv/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/apc.so/usr/local/php/lib/php/extensions/ PECL

Then we edit the php.ini file for configuration, please add the following code to the php.ini:

Extension_dir = "/usr/local/php/lib/php/extensions/pecl" extension = apc.so; apcapc.enabled = 1apc.shm_segments = 1apc.shm_size = 64apc.optimization = 1apc.num_files_hint = 0apc.ttl = 0apc.gc_ttl = 3 600apc.cache_by_default = On

This restarts Apache to be displayed in the Phpinfo () message.

2. Installation Configuration Eaccelerator

The predecessor of Eaccelerator is actually truck-mmcache, because the person who develops truk-mmcache is zend to pacified, so the person who develops eaccelerator inherits some characteristics of Truk-mmcache, Design the Eaccelerator accelerator. Install the following:

$wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2$ TAR-JXF eaccelerator-0.9.5.tar.bz2$ CD eaccelerator-0.9.5$/usr/local/php/bin/phpize$./configure–enable-eaccelerator= shared–with-php-config=/usr/local/php/bin/php-config$ make$ make install$ mv/usr/local/php/lib/php/extensions/ No-debug-non-zts-20060613/eaccelerator.so/usr/local/php/lib/php/extensions/pecl

Add the following code to the php.ini file

Extension = eaccelerator.so; Eacceleratoreaccelerator.shm_size = "Eaccelerator.cache_dir" = "/tmp/eaccelerator" eaccelerator.enable = "1" Eaccelerator.optimizer = "1" eaccelerator.check_mtime = "1" eaccelerator.debug = "0" Eaccelerator.filter = "" Eaccelerator.shm_max = "0" Eaccelerator.shm_ttl = "0" Eaccelerator.prune_period = "0" eaccelerator.shm_only = "0" eaccelerator.compress = "1" eaccelerator.compress_level = "9" Create cache directory, restart Apache$mkdir/tmp/eaccelerator$chmod 777/tmp/ Eaccelerator$/usr/local/apache/apachectl restart

Check whether the installation was successful at Phpinfo ().


3. Installation Configuration XCache

XCache as the people develop their own things, small rookie I also feel proud, and XCache both in speed and performance are good. Let's try it now!

$wget Http://xcache.lighttpd.net/pub/releases/1.2.2/xcache-1.2.2.tar.gz$tar Xvzf XCACHE-1.2.2.TAR.GZ$CD xcache-1.2.2$/usr/local/php/bin/phpize$./configure–enable-xcache–enable-xcache-coverager–with-php-config=/usr/ Local/php/php-config$make$sudo make Install$sudo mv/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ Xcache.so/usr/local/php/lib/php/extensions/pecl

To add configuration information in php.ini:

extension = xcache.so; xcachexcache.admin.user =   "admin" xcache.admin.pass =  "(Execute)  echo  ' (Your password) ' |md5sum (obtained ciphertext)"; xcache.size =  24Mxcache.shm_scheme =  "Mmap" Xcache.count = 2xcache.slots = 8kxcache.ttl  = 0xcache.gc_interval = 0xcache.var_size = 8Mxcache.var_count =  1xcache.var_slots = 8kxcache.var_ttl = 0xcache.var_maxttl = 0xcache.var_gc_ Interval = 300xcache.test = offxcache.readonly_protection = onxcache.mmap_path  =  "/tmp/xcache" xcache.coredump_directory =  "" Xcache.cacher = onxcache.stat  = onxcache.optimizer = off;xcache.coverager = onxcache.coveragedump_directory  =  "" Create cache directory, restart apache$mkdir /tmp/xcache$chmod 777 /tmp/xcache$/usr/local/apache/bin/ Apachectl restart 


Third, Comparison

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/41/43/wKiom1PR_33we3c2AAOnbhWEdYI574.jpg "title=" Cache.png "alt=" Wkiom1pr_33we3c2aaonbhwedyi574.jpg "/>

Transferred from: http://www.vpser.net/opt/apc-eaccelerator-xcache.html



This article is from the "Share Your Knowledge" blog, so be sure to keep this source http://skypegnu1.blog.51cto.com/8991766/1530095

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.