About PHP accelerated eaccelerator, Xcache, APC, and Zend Optimizer

Source: Internet
Author: User
Tags apc zts
Previously only focused on Zend Optimizer, because the high fat book is so taught, but encountered a wonderful company's face questions you know how many PHP accelerator/cache, I suddenly stared, because I know the php5.2.x only used Zend Optimizer, and encrypted PHP programs can only be run under Zend Optimizer. But php5.3.x the above version, Zend Optimizer can not support, let alone eaccelerator, Xcache, APC. Zend Guard Loader can support more than php5.3.x version, and the latest php5.5.x version, the official website said the built-in Zend guard, so do not phper focus on the accelerator. Since the encounter such a problem, but also from the online summary of things, netizens have seen on the line, do not have to test.

Which one does it install? What is the impact on performance? Have time to test it.

Seen from Elsewhere.

If the program environment is not necessary Zend Optimizer, the preferred PECL-APC (which is incompatible with Zend Optimizer).
Summarize:
1.PHP buffering (acceleration) preferred PECL-APC, with excellent compatibility and performance.
2. If your PHP environment requires Zend Optimizer, install eaccelerator and adjust the compression level of Zend Optimizer to 0.

Zend Optimizer is a code-optimized module that optimizes PHP code by optimizing the code generated by the running compiler (Run-time Compiler) before it is finally executed. Code performance can be increased by 40% to 100%, from this point on, should not have a strong caching capabilities, have not read the source, do not know whether the cache and the quality of the cache.
Eaccelerator is a module that caches the compiled PHP code in the share memory. By accessing the shared memory, the compiled code can be obtained and executed directly to improve the efficiency of PHP, which is much more efficient. At the same time, Eaccelerator can also cache the data into the file, this part because it is the operation of the file, I think for most of the file cache, the principle is similar, performance is similar.
The APC principle is similar to the eaccelerator, so the difference is not small. Not by modifying the parameters of the detailed test, can not see the pros and cons of both. So take one.

Three free PHP accelerators: APC, Eaccelerator, xcache comparison

Introduction 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 delivery request to mod_php.
3. mod_php Locate the disk file and load it into memory.
4, mod_php compiled source code becomes opcode tree.
5, mod_php execution 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.

Second, PHP accelerator installation and Configuration

1. Installation Configuration APC

APC Full name is alternative PHP cache, the official translation is called "Optional PHP cache", it is an extension in PHP pecl, it seems that Facebook is using it, the following start 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–enable-apc-mmap–with-php-config=/usr/local/php/bin/php-config
$make
$sudo 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
; 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

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

2. Installation Configuration Eaccelerator

The predecessor of the

Eaccelerator was actually truck-mmcache, because the person who developed Truk-mmcache was zend to pacified, so the people who developed Eaccelerator inherited some features 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
$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 a cache directory and restart Apache

$sudo Mkdir/tmp/eaccelerator
$sudo chmod 777/tmp/eaccelerator
$sudo/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
; XCache
Xcache.admin.user = "Admin"
Xcache.admin.pass = "(Execution) echo ' (Your password) ' |md5sum (ciphertext obtained)"
;
Xcache.size = 24M
Xcache.shm_scheme = "Mmap"
Xcache.count = 2
Xcache.slots = 8k
Xcache.ttl = 0
Xcache.gc_interval = 0

Xcache.var_size = 8M
Xcache.var_count = 1
Xcache.var_slots = 8k
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 a cache directory and restart Apache

$sudo Mkdir/tmp/xcache
$sudo chmod 777/tmp/xcache
$sudo/usr/local/apache/bin/apachectl Restart

Check out the phpinfo () information now!

Third, the PHP accelerator test

1. Test environment

Hardware: AMD Athlon X2 Dual Core Processor 4400+ @ 2.2GHz CPU, 2GB memory. 160GB SATA HDD

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

Test instruction: ab-c5-n3000 http://example.com/(We use Apache Benchmark (AB) tool, concurrent connection is 5, 3,000 requests)

2. Test results

No accelerator:

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. Summary of results

Request time (seconds) Single request time (milliseconds) Maximum memory consumption (MB) Minimum memory consumption (MB)
None 10.41 96.08 24 24
Apc 30.45 32.84 21st 21st
Eaccelerator 31.26 31.99 23 18
XCache 30.28 33.02 29 19

Iv. Summary of PHP Accelerator comparison results

1, the test results eaccelerator in the request time and memory occupation of the synthesis is the best.

2, through the test to obtain the use of accelerators than no accelerator in the request time is about 3 times times faster.

3, through the official observation, XCache is the fastest update, which also shows the most development.

The above is a summary of the results, you may ask me in the end use that accelerator good? I can only tell you, first of all, with a certain better than not, and then each accelerator has some tunable parameters, so depending on your system environment, then, I personally think you can study in detail under Eaccelerator and XCache, the two potential is still very large, Finally, I made a result diagram from the Comparative professional testing website:

Original link Address: http://www.vpser.net/opt/apc-eaccelerator-xcache.html

The above describes the PHP accelerated eaccelerator, Xcache, APC and Zend Optimizer, including aspects of the content, I hope to be interested in the PHP tutorial friends helpful.

  • 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.