Three free PHP accelerators: APCeAcceleratorXCache comparison

Source: Internet
Author: User
Tags apc zts
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 transmission requests

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 transmission requests

I. PHPAcceleratorIntroduction

PHPAcceleratorTo improve PHP Execution efficiency and cache the PHP operation code, you can directly call the PHP operation code without parsing and conversion. 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.

PHPAcceleratorThe fourth step is 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 quickly? So the bottleneck here is that PHP's repeated compilation affects both speed and server load. To solve this problem, PHPAcceleratorThis was born.

Ii. PHPAcceleratorInstallation 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 and the following is the installation (ubuntu environment ):
$ 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-mmap-with-php-config =/usr/local/php/bin/php-config
$ Make
$ Sudo make install

Next we will configure APC again, because my PECL extension path has changed, so I have to move the compiled file:
$ Sudo mv/usr/local/php/lib/php/extension/ no-debug-non-zts-20060613/apc. so/usr/local/php/lib/php/extensions/PECL

Then edit the php. ini file for configuration. Add the following code to php. ini:
Extension_dir = "/usr/local/php/lib/php/extensions/PECL"
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

In this way, apache is restarted and displayed in phpinfo.

2. install and configure eAccelerator

The predecessor of eAccelerator is actually truck-mmcache. Because the person who developed truk-mmcache was Zend to the security group, the person who developed the eAccelerator inherited some features of truk-mmcache and designed the eAccelerator.Accelerator. 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
$ Eaccelerator-0.9.5 cd
$/Usr/local/php/bin/phpize
$./Configure-enable-eaccelerator = shared-with-php-config =/usr/local/php/bin/php-config
$ Make
$ Sudo make install
$ Sudo 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
; 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
$ Xcache-1.2.2 cd
$/Usr/local/php/bin/phpize
$./Configure-enable-xcache-coverager-with-php-config =/usr/local/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

Add configuration information in php. ini:

Extension = xcache. so
; Xcache
Xcache. admin. user = "admin"
Xcache. admin. pass = "(execute) echo '(your password)' | md5sum (obtained ciphertext )"
;
Xcache. size = 24 M
Xcache. shm_scheme = "mmap"
Xcache. count = 2
Xcache. slots = 8 k
Xcache. ttl = 0
Xcache. gc_interval = 0

Xcache. var_size = 8 M
Xcache. var_count = 1
Xcache. var_slots = 8 k
Xcache. var_ttl = 0
Xcache. var_maxttl = 0
Xcache. var_gc_interval = 300
Xcache. test = Off
Xcache. readonly_protection = On
Xcache. mmap_path = "/tmp/xcache"
Xcache. coredump_directory = ""
Xcache. cacher = On
Xcache. stat = On
Xcache. optimizer = Off
;
Xcache. coverager = On
Xcache. 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 the phpinfo () information!

Iii. PHPAcceleratorTest

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

NoneAccelerator:

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 secondd: 10.41 [#/sec] (mean)
Time per request: 480.425 [MS] (mean)
Time per request: 96.085 [MS] (mean, internal SS all concurrent requests)
Transfer rate: 226.23 [Kbytes/sec] canceled ed
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
Total: 181 479 186.0 444
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)

APCAccelerator:

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 secondd: 30.45 [#/sec] (mean)
Time per request: 164.217 [MS] (mean)
Time per request: 32.843 [MS] (mean, internal SS all concurrent requests)
Transfer rate: 661.84 [Kbytes/sec] canceled ed
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)

EAcceleratorAccelerator:

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 secondd: 31.26 [#/sec] (mean)
Time per request: 159.973 [MS] (mean)
Time per request: 31.995 [MS] (mean, internal SS all concurrent requests)
Transfer rate: 679.39 [Kbytes/sec] canceled ed
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
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)

XCacheAccelerator:

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 secondd: 30.28 [#/sec] (mean)
Time per request: 165.127 [MS] (mean)
Time per request: 33.025 [MS] (mean, internal SS all concurrent requests)
Transfer rate: 658.19 [Kbytes/sec] canceled ed
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
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. PHPAcceleratorComparisonResult Summary

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

2. Test and useAcceleratorBiwuAcceleratorThe request time is about three times faster.

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

The above is the summary result. You may ask me whichAcceleratorOkay? I can only tell you that, first, it is better to use it than to use it.AcceleratorThere are also some parameters that can be tuned, So it depends on your system environment. Then, I personally think you can study eAccelerator and XCache in detail, these two models have great potential.ComparisonThe professional testing website provides a result chart:

Http://killker.com/blog? P = 94

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.