Three free PHP accelerators: APC, eAccelerator, and XCache performance comparison

Source: Internet
Author: User
Tags apc
I. Introduction to the PHP accelerator is a PHP accelerator designed to improve PHP execution efficiency and cache the PHP operation code so that PHP does not need to be parsed or converted after execution. you can directly call the PHP operation code, this increases the speed. The execution process of mod_php requests and responses in Apache: 1. Apache receives requests. 2. Apache sends the request to mod_php. I. Introduction to the PHP accelerator

The PHP accelerator is a PHP operation code cached to improve PHP execution efficiency. in this way, PHP does not need to be parsed or converted for subsequent execution. you can directly call the PHP operation code, this increases the speed.

In Apache, the execution process of requests and responses using mod_php is as follows:

1. Apache receives the request. 2. Apache sends the request to mod_php. 3. locate the disk file in mod_php and load it to the memory. 4. mod_php compiles the source code into the opcode tree. 5. run the opcode tree in mod_php.

The PHP accelerator corresponds to step 4, which aims to prevent PHP code from being repeatedly compiled every time PHP requests are made, because on high-traffic websites, a large amount of compilation is often not executed fast, so the bottleneck here is that PHP's repeated compilation affects both speed and server load. to solve this problem, the PHP accelerator was born.

II. PHP accelerator installation and configuration

1. install and configure APC

The full name of APC is Alternative PHP Cache, which is officially translated as "optional PHP Cache". It is an extension in php pecl. it seems that facebook is using it. to install this extension, refer to this article: optional PHP Cache APC analysis-installation, configuration and working principle.

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

 extension = apc.so ; APC apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 64 apc.optimization = 1 apc.num_files_hint = 0 apc.ttl = 0 apc.gc_ttl = 3600 apc.cache_by_default = on

After apache is restarted, the APC and its configuration information are displayed in the phpinfo () information.

2. install and configure eAccelerator

The predecessor of eAccelerator is actually truck-mmcache. because the person who developed truk-mmcache was Zend to Zhaoxing, the person who developed the eAccelerator inherited some features of truk-mmcache, the eAccelerator accelerator is designed. The installation is as follows:

 $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 $sudo make install

Add the following code to the php. ini file:

 extension = eaccelerator.so ; eAccelerator eaccelerator.shm_size = "16" 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 and restart apache

$sudo mkdir /tmp/eaccelerator$sudo chmod 777 /tmp/eaccelerator$sudo /usr/local/apache/apachectl restart

Check whether the installation is successful in phpinfo.

3. install and configure XCache

XCache is developed by Chinese people. I am also proud to be a novice, and XCache is doing well in both speed and performance. Now let's try it!

$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

Add configuration information in php. ini:

Extension = xcache. so; xcachexcache. admin. user = "admin" xcache. admin. pass = "(executed) 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 and restart apache

$sudo mkdir /tmp/xcache$sudo chmod 777 /tmp/xcache$sudo /usr/local/apache/bin/apachectl restart

Check whether the phpinfo () information has been successfully installed!

III. PHP accelerator testing

1. test environment

Hardware: AMD Athlon 64X2 Dual Core Processor 4400 + @ 2.2 GHz CPU, 2 GB memory. 160 gb sata hard drive

Software: Linux Ubuntu server Gutsy 7.10, Apache 2.2.4, MySQL 5.0.45, and PHP 5.2.3

Test Command: AB-c5-n3000 http://example.com/(we are using the Apache Benchmark (AB) tool with concurrent connections of 5 to requests)

2. test results

No accelerators:

 Document Path: / Document Length: 21757 bytes Concurrency Level: 5 Time taken for tests: 288.255212 seconds Complete requests: 3000 Failed requests: 0 Write errors: 0 Total transferred: 66777000 bytes HTML transferred: 65271000 bytes Requests per second: 10.41 [#/sec] (mean) Time per request: 480.425 [ms] (mean) Time per request: 96.085 [ms] (mean, across all concurrent requests) Transfer rate: 226.23 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.5 0 19 Processing: 181 479 186.0 444 1822 Waiting: 166 461 184.7 427 1708 Total: 181 479 186.0 444 1822 Percentage of the requests served within a certain time (ms) 50% 444 66% 525 75% 577 80% 619 90% 732 95% 819 98% 946 99% 1012 100% 1822 (longest request)

APC accelerator:

 Document Path: / Document Length: 21757 bytes Concurrency Level: 5 Time taken for tests: 98.530068 seconds Complete requests: 3000 Failed requests: 0 Write errors: 0 Total transferred: 66777000 bytes HTML transferred: 65271000 bytes Requests per second: 30.45 [#/sec] (mean) Time per request: 164.217 [ms] (mean) Time per request: 32.843 [ms] (mean, across all concurrent requests) Transfer rate: 661.84 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 2 Processing: 58 163 71.2 155 2452 Waiting: 53 158 69.6 150 2329 Total: 58 163 71.2 155 2452 Percentage of the requests served within a certain time (ms) 50% 155 66% 178 75% 193 80% 204 90% 235 95% 258 98% 285 99% 302 100% 2452 (longest request)

EAccelerator accelerator:

 Document Path: / Document Length: 21757 bytes Concurrency Level: 5 Time taken for tests: 95.983986 seconds Complete requests: 3000 Failed requests: 0 Write errors: 0 Total transferred: 66777000 bytes HTML transferred: 65271000 bytes Requests per second: 31.26 [#/sec] (mean) Time per request: 159.973 [ms] (mean) Time per request: 31.995 [ms] (mean, across all concurrent requests) Transfer rate: 679.39 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 3 Processing: 57 159 91.3 148 3830 Waiting: 50 152 89.8 142 3704 Total: 57 159 91.3 148 3830 Percentage of the requests served within a certain time (ms) 50% 148 66% 174 75% 193 80% 205 90% 239 95% 263 98% 289 99% 309 100% 3830 (longest request)

XCache accelerator:

 Document Path: / Document Length: 21757 bytes Concurrency Level: 5 Time taken for tests: 99.76300 seconds Complete requests: 3000 Failed requests: 0 Write errors: 0 Total transferred: 66777000 bytes HTML transferred: 65271000 bytes Requests per second: 30.28 [#/sec] (mean) Time per request: 165.127 [ms] (mean) Time per request: 33.025 [ms] (mean, across all concurrent requests) Transfer rate: 658.19 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 2 Processing: 59 164 83.4 155 3367 Waiting: 52 156 66.4 148 1802 Total: 59 164 83.4 155 3367 Percentage of the requests served within a certain time (ms) 50% 155 66% 178 75% 196 80% 206 90% 237 95% 263 98% 287 99% 305 100% 3367 (longest request)

3. Result summary

Request time (SEC) Time per request (MS) Maximum memory usage (MB) Minimum memory usage (MB)
None 10.41 96.08 24 24
APC 30.45 32.84 21 21
EAccelerator 31.26 31.99 23 18
XCache 30.28 33.02 29 19
IV. Summary of comparison results of PHP accelerators

1. test results show that the eAccelerator is the best in terms of the combination of request time and memory usage.

2. the test result shows that the request time of the accelerator is about three times faster than that of the non-accelerator.

3. according to official observations, XCache is the fastest updated, which also shows the most promising development.

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.