linux下配置eAccelerator加速PHP的实例参考

发布时间:2020-03-13编辑:脚本学堂
本文介绍下,在linux系统中,配置eAccelerator以加速PHP的方法,有需要的朋友参考下。

配置eAccelerator加速PHP,步骤如下。

1、安装eAccelerator:
 

复制代码 代码示例:
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php5/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php5/bin/php-config
make
make install
cd ../
mkdir -p /usr/local/php5/eaccelerator_cache
vim /usr/local/php5php/etc/php.ini

2、按shift+g键跳到配置文件的最末尾,加上以下配置信息:
 

复制代码 代码示例:
[eaccelerator]
end_extension="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/php5/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

3,重启php-fpm报错
 

复制代码 代码示例:
[root@server4 no-debug-non-zts-20090626]# service php-fpm restart
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?
Starting php-fpm eAccelerator: Could not allocate 67108864 bytes, the maximum size the kernel allows is 33554432 bytes. Lower the amount of memory request or increase the limit in /proc/sys/kernel/shmmax.
[15-Apr-2013 00:10:42] NOTICE: PHP message: PHP Warning:  [eAccelerator] Can not create shared memory area in Unknown on line 0
[15-Apr-2013 00:10:42] NOTICE: PHP message: PHP Fatal error:  Unable to start eAccelerator module in Unknown on line 0
 failed

解决办法:php.ini中设置的eAccelerator,eaccelerator.shm_size=”64″,解释:eaccelerator可使用的共享内存大小(单位为MB),即64M
eaccelerator.shm_size="64"

在Linux下,单个进程的最大内存使用量受/proc/sys/kernel/shmmax中设置的数字限制(单位为字节)  /proc/sys/kernel/shmmax = 33554432 (32M)
修改方法:
 

复制代码 代码示例:
vim/etc/sysctl.conf
kernel.shmmax = 128000000
syscatl -p 

或修改参数:
eaccelerator.shm_size="32"
重启php-fpm 问题解决。