环境:centos5
确保系统已经安装好php-devel、autoconf、automake、m4、libtool、 gcc(预编译用) make(编译用)等软件,可使用rpm -q 软件包名查看,如未安装,使用yum -y install 软件包名进行安装。
eaccelerator官方网站:http://eaccelerator.net/
安装配置步骤如下:
1)下载源码包:本地下载地址:
# cd /usr/local/src
# wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zip
2)解压源码包
# unzip eaccelerator-0.9.5.3.zip
#cd eaccelerator-0.9.5.3
3)利用phpize进行php程序的预处理
#phpize
4)预编译设置:
#./configure --enable-eaccelerator=shared --with-php-config=/usr/bin/php-config
5)编译:
# make
6)编译成功后安装
# make install
此时这个新编译的模块会被放置到/usr/lib/php/modules/eaccelerator.so中
7)修改php.ini和预先加载PHP模块
vi /etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
[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.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
预先加载php模块
#vi /etc/ld.so.conf
#ldconfig <–把模块导入高速缓存
在文件尾添加
/usr/lib/php/modules
8)建立eaccelerator的暂存数据
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator
9)使用ab命令测试一下网站效率,如下:
[root@www tmp]# ab -dkS -n100 -c100 http://localhost/phpinfo.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Apache
Server Hostname: localhost
Server Port: 80
Document Path: /phpinfo.php
Document Length: 48658 bytes
Concurrency Level: 100
Time taken for tests: 1.52041 seconds
Complete requests: 100
Failed requests: 1
(Connect: 0, Length: 1, Exceptions: 0)
Write errors: 0
Keep-Alive requests: 0
Total transferred: 4879895 bytes
HTML transferred: 4865795 bytes
Requests per second: 95.05 [#/sec] (mean)
Time per request: 1052.041 [ms] (mean)
Time per request: 10.520 [ms] (mean, across all concurrent requests)
Transfer rate: 4529.29 [Kbytes/sec] received
Connection Times (ms)
min avg max
Connect: 0 3 19
Processing: 423 647 1016
Total: 423 650 1035
10)重新apache
# apachectl restart
11)验证eAccelerator是否生效
在命令行下运行
#php -v
如果输出想如下的信息
[root@www tmp]# php -v
PHP 5.1.6 (cli) (built: Jul 16 2008 19:53:00)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
[root@www tmp]#
证明已经加载成功,且生效
12)重新使用ab命令测试一下网站效率,如下:
[root@www tmp]# ab -dkS -n100 -c100 http://localhost/phpinfo.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Apache
Server Hostname: localhost
Server Port: 80
Document Path: /phpinfo.php
Document Length: 51378 bytes
Concurrency Level: 100
Time taken for tests: 0.551591 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Keep-Alive requests: 0
Total transferred: 5151900 bytes
HTML transferred: 5137800 bytes
Requests per second: 181.29 [#/sec] (mean)
Time per request: 551.591 [ms] (mean)
Time per request: 5.516 [ms] (mean, across all concurrent requests)
Transfer rate: 9120.89 [Kbytes/sec] received
Connection Times (ms)
min avg max
Connect: 0 12 16
Processing: 12 237 535
Total: 12 249 551
[root@www tmp]#
13)总结,从第9和第12的Time taken for tests:项目,可以看出,加载eAccelerator后效率提高了快1倍。
没有评论:
发表评论