- 浏览: 207879 次
- 性别:
- 来自: 宇宙
文章分类
最新评论
-
naryCC:
虽然没有smarty那么方便,但是由于我们的环境太老不得不使用 ...
SmartTemplate -
victorwmh:
我们项目是Java项目,但数据源来自不同的地方,有些还是合作单 ...
和C++相对应Java的CheckSum -
cuisuqiang:
那你们到底是Java项目还是C++的项目?
和C++相对应Java的CheckSum -
david.org:
attempt to write a readonly dat ...
linux+apache+subversion版本控制 -
victorwmh:
wellee 写道兄弟,我怎么配置ZendDebugger老是 ...
Zend Debugger和Zend Optimizer配置(Windows)
一、PHP加速器介绍
PHP加速器是一个为了提高PHP执行效率,从而缓存起PHP的操作码,这样PHP后面执行就不用解析转换了,可以直接调用PHP操作码,这样速度上就提高了不少。
Apache中使用mod_php的请求、响应执行流程:
1、Apache接收请求。
2、Apache传递请求给mod_php。
3、mod_php定位磁盘文件,并加载到内存中。
4、mod_php编译源代码成为opcode树。
5、mod_php执行opcode树。
PHP加速器相应的就是第四步,它的目的就是防止PHP每次请求都重复编译PHP代码,因为在高访问量的网站上,大量的编译往往没有执行速度快呢?所以这里面有个瓶颈就是PHP的重复编译既影响了速度又加载了服务器负载,为了解决此问题,PHP加速器就这样诞生了。
二、PHP加速器安装与配置
1、安装配置APC
APC全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”,它是PHP PECL中的一个扩展,好像facebook在使用它。在http://pecl.php.net/package/APC中包含了所有apc安装包,你可以根据自己的需求选择相应的版本。state包含stable和beta两种状态,下载安装包时请留意。
# tar zxvf APC-3.1.9.tgz
# cd APC-3.1.9
# /usr/local/php5/bin/phpize
# ./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php5/bin/php-config
# make && make install
# cp /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/apc.so /usr/local/php5/lib/php/extensions/apc.so
注:#/usr/local/php5/bin/phpize用于生成安装configure文件。
在配置文件php.ini的文件末尾加入以下内容:
[apc] extension=apc.so apc.enabled = 1 apc.cache_by_default = on apc.shm_segments = 1 apc.shm_size = 128 M apc.ttl = 7200 apc.user_ttl = 7200 apc.num_files_hint = 1024 apc.write_lock = On apc.gc_ttl=3600 apc.ttl=0 apc.mmap_file_mask=/tmp/apc.XXXXXX
2、安装配置eAccelerator
eAccelerator的前身其实是truck-mmcache,因为开发truk-mmcache的人被Zend给招安了,所以开发eAccelerator的人继承了truk-mmcache的一些特性,设计出eAccelerator加速器。
# 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/php5/bin/phpize
# ./configure -enable-eaccelerator=shared -with-php-config=/usr/local/php5/bin/php-config
# make && make install
# cp /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so /usr/local/php5/lib/php/extensions/
创建缓存目录:
# mkdir /tmp/eaccelerator
# chmod 777 /tmp/eaccelerator
在配置文件php.ini的文件末尾加入以下内容:
[eAccelerator] extension = eaccelerator.so 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"
3、安装配置XCache
值得一提的是XCache由国人开发,而且在速度和性能上都有不错的表现。
# 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/php5/bin/phpize
# ./configure -enable-xcache -enable-xcache-coverager -with-php-config=/usr/local/php5/php-config
# make && make install
# cp /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/xcache.so /usr/local/php5/lib/php/extensions/
创建缓存目录:
# mkdir /tmp/xcache
# chmod 777 /tmp/xcache
在配置文件php.ini的文件末尾加入以下内容:
[xcache] extension = xcache.so xcache.admin.user = "admin" xcache.admin.pass = "(执行) echo ’(你的密码)’|md5sum(得出的密文)" 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 = ""
三、PHP加速器测试
1、测试环境
硬件: AMD Athlon 64 X2 Dual Core Processor 4400+ @ 2.2GHz CPU, 2GB 内存. 160GB SATA 硬盘
软件: Linux Ubuntu server Gutsy 7.10, Apache 2.2.4, MySQL 5.0.45 和 PHP 5.2.3
测试指令: ab -c5 -n3000 http://example.com/ (使用的是Apache Benchmark (ab) 工具,并发连接为5,3000次请求)
2、测试结果
无加速器:
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加速器:
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加速器:
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加速器:
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、结果摘要
请求时间(秒) | 单次请求时间(毫秒) | 最大内存占用(MB) | 最小内存占用(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 |
四、PHP加速器比较结果总结
1、通过测试得出eAccelerator在请求时间和内存占用综合方面是最好的。
2、通过测试得出使用加速器比无加速器在请求时间快了3倍左右。
3、通过各个官方观察,XCache是更新最快。
以上是总结结果,你也许会问我到底用那个加速器好呢?我只能告诉你,首先,用一定比不用好,其次每个加速器还有一些可以调优的参数,所以要根据你的系统环境而定,然后,我个人觉得你可以详细研究下eAccelerator和XCache,这两款潜力还是很大的。
专业测试网站对比图:
本文内容来自:http://killker.com/blog/?p=94
发表评论
-
SmartTemplate
2012-12-22 12:59 1623基本方法 SmartTemplate:: ... -
PHP webservice
2012-04-02 10:08 0http://www.blueidea.com/tech/pr ... -
常用webservice地址
2012-04-02 08:36 1227天气预报Web Service,数据来源于中国气象局 En ... -
yum httpd php php-mysql
2012-02-20 11:10 1502对于CentOS服务器yum是一个非常好的工具,尤其是在32位 ... -
用PHP写的一个web升级脚本
2011-10-21 14:31 1150管理web项目一直是件很困难的事情,程序使用时间越长里面的sp ... -
Postfix替代sendmail发送邮件
2011-08-18 10:52 3577基础知识 MUA: Mail User Ag ... -
Wordpress插件开发
2011-08-11 15:33 1232wordpress能成为当今用户最多的blog程序,其强大的插 ... -
linux+cacti安装配置,监控主机性能
2011-07-21 15:21 2251一、Cacti概述 1、cacti是用php语言 ... -
PHP正则表达式
2011-07-01 18:14 1140一、概述 正则表达式是进行模式匹配和文本操纵的一种复杂而 ... -
PHP表单及验证
2011-06-30 17:49 2247一、概述 PHP在处理一个页面时,它都会检查URL和 ... -
PHP程序员如何突破成长瓶颈
2011-06-04 15:23 942转:http://www.builder.com.cn/201 ... -
PHP Session原理分析及使用
2011-06-02 16:49 6057之前在一个叫魔 ... -
国外主流PHP框架对比
2011-05-25 10:21 1147【转自】http://tech.it168.c ... -
用memcache.php监测Memcached的使用情况
2010-12-27 10:25 1347最新的memcache pecl中,新增了一个memcache ... -
Linux下安装Memcached及php的memcache扩展库
2010-12-26 18:34 2012Memcache是什么? Memcach ... -
【转】PHP 实现多服务器共享 SESSION 数据
2010-12-14 09:33 807一、问题起源 稍大一 ... -
Zend Debugger和Zend Optimizer配置(Windows)
2010-06-15 12:26 3159Zend Debugger和Zend Optimizer的单个 ... -
PHP常见问题
2010-05-21 07:59 8990、字符串与数字比较,非数字开头的字符串与0比较时返回真 ...
相关推荐
Memcache-eAccelerator-APC-Xcache-Redis 五种php缓存加速器特点浅析.docx
主要介绍了php加速缓存器opcache,apc,xcache,eAccelerator原理与配置方法,结合实例形式分析了php加速缓存器opcache,apc,xcache,eAccelerator的基本功能、原理及扩展配置相关操作技巧,需要的朋友可以参考下
php加速器eaccelerator概述.docx
php缓存加速器eAccelerator配置详解
php缓存加速器eAccelerator配置详解
eaccelerator加速器,eaccelerator版本有0952 0953 0960 0961 喜欢用哪个就用哪个,里面有包含thread safe(线程安全版)eaccelerator_ts.dll 和no thread safe(非线程安全版),附带配置示例和eaccelerator管理文件...
注意:在不久的将来, 此加速器可能变得更好,据说PHP6.X版本中要整合此加速器. 安装过程十分简单安装步骤: 1.下载对应你PHP版本的.dll文件下载地址: apc .dll for PHP4.X apc.dll for PHP5.X 然后重命名为php_apc.dll ...
在linux上建立PHP的加速器eAccelerator.pdf
格式:eAccelerator_v1_0_svn427_for_v5_3_5-VC6 eAccelerator支持php5.3.5加速器及配置,内有PHP.INI的配置文档
PHP中有eAccelerator、memcached、xcache、APC 4个加速、缓存扩展,下面给大家介绍下其区别,一起看看吧!... eAccelerator是一个自由开放源码PHP加速器,优化和动态内容缓存,提高了PHP脚本的缓存性能,使
eAccelerator专门为PHP开发,是目前较为主流的可使用在PHP之中的缓存加速工具. eAccelerator的主要功能: 1. 缓存PHP文件的执行代码:在被缓存的代码再次被调用时,将直接从内存读取,从而在很大程度了PHP运行的...
php加速器,加速您的PHP程序。在php.ini中增加eAccelerator.dll的装载!
eAccelerator for windows php v5.3.XX VC9 PHP加速模块下载, 这个东西是目前PHP加速最好用的缓存模块了, 这个是windows平台下使用的已经编译好的eAccelerator.dll 文件, TS 和NTS 2个版本.
在Windows环境下编译、配置 eAccelerator 加速PHP 附eAccelerator.dll for php5.3.8 nts下载: http://www.oaxueyuan.com/compiled-in-a-windows-environment-configuration-eaccelerator-php-acceleration.html ...
eAccelerator0953_5.2.10.dll
PHP加速器安装方法 eAccelerator.dll,放在D:\MYOA\bin下(以您实际安装路径为准) 然后修改D:\MYOA\bin\php.ini,查找到date.timezone = PRC 在这之后加入以下内容(其中的路径,根据您实际安装路径修改):