[EAC] PHP 预编译加速: eAccelerator的安装和性能比较
上次尝试安装Wikipedia的镜像的时候,了解到了eAccelerator已经是很常用的PHP平台预编译加速的手段了。今天在自己机器上尝试安装了一下,备忘如下:
获得源代码: http://bart.eaccelerator.net/source/ 编译:需要有autoconf支持,解包后在源程序目录下:
/usr/local/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/bin/php-config make sudo make install配置增加如下:sudo vi /usr/local/lib/php.ini
extension_dir = "/usr/local/lib/php/extensions" extension="/no-debug-non-zts-20060613/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"
2006-06-03更新 在apache 2.2的升级过程中:发现php的相关模块都需要重新编译 需要注意包含哪个目录下的 eaccelerator.so 文件 /usr/local/lib/php/extensions$ ls -1 no-debug-non-zts-20020429 no-debug-zts-20020429 否则eAccelerator会无法生效, 我测试的结果在apache 2.2下eAccelerator的效果比apache 1.3下还差一些;
最好创建专用的缓存目录:
sudo mkdir /tmp/eaccelerator sudo chmod 0777 /tmp/eaccelerator重启一下apache: sudo /home/apache/bin/apachectl restart 通过[phpinfo()](http://www.chedong.com/phpMan.php/phpinfo)已经可以看到:eAccelerator启用了 [chedong@chedong eaccelerator-0.9.5.3]$ php -v PHP 5.2.8 (cli) (built: Jan 14 2009 02:44:39) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies **with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator**
用phpinfo这个脚本本身还做了一下性能对比测试:对于纯php代码(不考虑数据库瓶颈/文件IO等操作)的运行效率的确有3-5倍的效率提升;
测试: /home/apache/bin/ab -c 20 -n1000 http://www.chedong.com/phpMan.php/phpinfo
**eAccelerator 启用** |**eAccelerator 关闭** Document Length: 32006 bytes |Document Length: 29136 bytes Concurrency Level: 20 |Concurrency Level: 20 Time taken for tests: 5.813 seconds |Time taken for tests: 23.896 seconds Complete requests: 1000 |Complete requests: 1000 Failed requests: **89** |Failed requests: **109** (Connect: 0, Length: 89, Exceptions: 0) | (Connect: 0, Length: 109, Exceptions: 0) Broken pipe errors: 0 |Broken pipe errors: 0 Total transferred: 32534962 bytes |Total transferred: 29578714 bytes HTML transferred: 32263316 bytes |HTML transferred: 29308693 bytes Requests per second: **172.03** [#/sec] (mean) |Requests per second: **41.85** [#/sec] (mean) Time per request: 116.26 [ms] (mean) |Time per request: 477.92 [ms] (mean) Time per request: **5.81** [ms] |Time per request: **23.90** [ms] Transfer rate: 5596.93 [Kbytes/sec] received |Transfer rate: 1237.81 [Kbytes/sec] received | Connnection Times (ms) |Connnection Times (ms) min mean[+/-sd] median max | min mean[+/-sd] median max **Connect: 0 19 12.1 17 72 |Connect: 0 91 58.9 89 424 Processing: 53 92 22.0 90 219 |Processing: 140 379 209.6 366 4078 Waiting: 39 89 21.9 88 218 |Waiting: 113 359 210.6 349 4076 Total: 53 111 16.4 109 251 |Total: 140 470 203.7 450 4321** | Percentage of the requests served within a certain time (ms) |Percentage of the requests served within a certain time (ms) ** 50% 109 | 50% 450 66% 110 | 66% 453 75% 111 | 75% 456 80% 116 | 80% 460 90% 130 | 90% 490 95% 145 | 95% 626 98% 158 | 98% 830 99% 167 | 99% 831 100% 251 (last request) | 100% 4321 (last request)**
2006-08-21 用yum安装autoconf时候出警告:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID db42a60e Public key for autoconf-2.59-5.noarch.rpm is not installed Retrieving GPG key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora GPG key at file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora (0x4F2A6FD2) is already installed按照[Dan的回复](https://oachs.it.gac.edu/wordpress/?p=128):修复一下 rpm --import /usr/share/rhn/RPM-GPG-KEY 然后再安装就可以了。The GPG keys listed for the “Fedora Core 4 - i386 - Base” repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository.
2006-11-03 升级PHP后,eAccelerator需要重新编译,并且设置扩展的公共根路径: ; Directory in which the loadable extensions (modules) reside. **extension_dir = “/usr/local/lib/php/extensions” extension="/no-debug-non-zts-20060613/eaccelerator.so" ** 否则会出现错误:
PHP Warning: Unknown(): Unable to load dynamic library './/usr/local/lib/php/extensions/no-debug-non-zts-20020429/eaccelerator.so' - .//usr/local/lib/php/extensions/no-debug-non-zts-20020429/eaccelerator.so: cannot open shared object file: No such file or directory in Unknown on line 0
💬 历史评论
以下 11 条评论从旧版 Movable Type 博客迁移而来。 原始评论时间:2002–2016 年。
robinz · 2006-05-25 16:30
可惜EAC现在对php5的支持不是太好.
eac对php加速的效果很明显的说~
Haohappy · 2006-07-01 18:30
在IO操作如文件包含(include,require)的时候效率提升很明显。不过eAccelerator有一个强劲的对手APC,后者由PHP创始人Rasmus Lerdorf在主持项目,将可能在PHP6中绑定发布。
bob · 2006-12-25 18:03
我也是按照eaccelerator网站的说法编译的,
但是加载的时候(php -v ) 确有这样的错误: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) ’eaccelerator.so’ in Unknown on line 0 PHP 5.2.0 (cli) (built: Dec 18 2006 14:47:43) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
不知道,是不是我编译的有问题呢?我的version 0.9.5
bob · 2007-01-02 10:15
还是不行啊, 我的路径是对的 : 我在 php.ini 里面的找到这样一行: extension_dir = “./” 我把他改成了 extension_dir = “/usr/local/lib/php/extensions/no-debug-non-zts-20060613/”
对于 eaccelerator ,make install之后 ,就是安装到上面的目录的。
我的PC 是RedHat9.0 ,其他的autoconf什么的,都是自带的。 执行phpize 的时候居然有点问题, 但是configure仍然生成了。 但是config.h 确实空的, 所以我改了一下: /* config.h.in. Generated automatically from configure.in by autoheader. */ #define MM_SEM_IPC 1 #define MM_SHM_IPC 1 #define EA_USERID 1
#define PHP_MAJOR_VERSION 5 #define PHP_MINOR_VERSION 2
编译就没有问题了。
能否说说你的编译过程,或者公布一下你的config.h 也好,多谢了。
石头 · 2007-01-17 23:26
想问问,eaccelerator编译成功,并开启,那PHP源码应该如何操作,应如何处理一下,我不能使用ZEND来编译,那可以使用什么编译器来编译,或者eaccelerator本身就可以编译PHP源码???
非常想了解,因为我eaccelerator已经开启了,但PHP程序的运行并没有得到提高,我对PHP不熟悉,是LINUX平台上的,帮朋友处理,光是放PHP的源码就可以直接加速么???
Ivan · 2007-02-15 01:22
问题1:我/usr/local/php4/bin/下已经有phpize这个文件,是不是说明我的主机已经具备安装eAccelerator的环境了? 问题2:php4是不是只能用eaccelerator-0.9.4,目前官方发布的最新版是eaccelerator-0.9.5。 问题3:一直搞不明白Zend扩展和PHP扩展有什么本质上的区别,我应该如何选择? 说明:基于源码编译的LAMP主机目前运行正常。 系统环境: OS:CentOS-4.4.ServerCD-i386 Apache:2.2.4 Mysql:4.0.26 PHP:4.3.11 ZendOptimizer:3.2.2
km3945 · 2007-04-20 11:09
eaccelerator 和 PHP5.21的异常类Exception有冲突, 加载eaccelerator 后 PHP抛出一个异常时会引发致命错误: Fatal error: Uncaught exception ‘Exception’ ……
xq · 2007-06-05 14:22
eaccelerator-0.9.5 做了很多改变 请看这 http://blog.csdn.net/xuqiang76/archive/2007/05/14/1608313.aspx
junphine · 2007-06-19 19:47
我在windows上装成功了,但开启了php的输出缓存压缩后,浏览器好像识别不了,返回的是乱码,怀疑是浏览器没有解压缩。不知道有谁遇到,如何解决。
笑容 · 2007-12-30 21:08
在win32下无法使用共享内存 真是遗憾的很啊。
在我的新网站 www.mikaa.net 上应用了。 用的是 debian 的服务器,感觉共享内存太爽了。哈
谢谢 车东的分享。
ncnynl · 2009-05-07 11:21
安装非常顺利,谢谢您的这篇教程