开始配置软件,具体软件安装,可以看 LAMP与LNMP加速与缓存优化(一)

vi     /application/php/lib/php.ini

lamp 

extension_dir = "/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/"

extension = memcache.so                                                                    //添加

extension = pdo_mysql.so

extension = imagick.so

/application/apache/bin/apachectl restart


lnmp

extension_dir = "/application/php5.3.27/lib/php/extensions/no-debug-non-zts-20090626/"

extension = memcache.so

extension = pdo_mysql.so

extension = imagick.so

pkill php-fpm                          //重启

/application/php/sbin/php-fpm


vim  index.php

<?php

        phpinfo();

?>

进入首页,ctrl+F搜索memcache   pdo_mysql  imagick,查看是否有


配置eaccelerator缓存 目录

mkdir   -p  /tmp/eaccelerator         可以用tmpfs内存文件系统或者固态硬盘

chown -R  nginx.nginx  /tmp/eaccelerator

chown -R  www.www   /tmp/eaccelerator


cat >> /application/php/lib/php.ini<<EOF   

[eaccelerator]

extension=eaccelerator.so

eaccelerator.shm_size="64"

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="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

EOF


# /application/php/bin/php -v

PHP 5.3.27 (cli) (built: Apr  3 2016 22:23:16)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

    with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerator  

模块已生效


# ls  /tmp/eaccelerator/

0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

find /tmp/eaccelerator/  -type f         //无文件,还未缓存


/application/apache/bin/apachectl restart    //重启服务  apache

find /tmp/eaccelerator/  -type f         

/tmp/eaccelerator/3/8/eaccelerator-86746.765166     //有缓存了


kill -USR2   `cat /app/logs/php-fpm.pid`          //  重启nginx

 find /tmp/eaccelerator/  -type f                     

/tmp/eaccelerator/e/3/eaccelerator-86746.763441


补充:   kill -9  进程号                killall  -9  进程号               pkill   进程名

#ps -ef  | grep php-fpm | awk '{print $2}'| xargs kill

/application/php/sbin/php-fpm

# ps -ef  | grep php-fpm   |  awk '{print  "kill "  $2} ' | bash 


eaccelerator 和xcache 二选一就可以

vi    xcache-1.3.2/xcache.ini

3 ;zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so  //注释掉

6 ;zend_extension_ts = c:/php/extensions/php_xcache.dll    //注释掉

8 extension = xcache.so   //取消注释  前面不要有空格

25 xcache.size  =                   128M

27 xcache.count =                 2          //CPU核心数cat /proc/cpuinfo |grep -c processor

31 xcache.ttl   =                     86400

33 xcache.gc_interval =        3600

36 xcache.var_size  =             0


cat   xcache-1.3.2/xcache.ini >> /application/php/lib/php.ini    //追加

/application/php/bin/php -v

PHP Warning:  Cannot load module 'XCache' because conflicting module 'eAccelerator' is already loaded in Unknown on line 0             //会有冲突报错

需要注释掉前面的eaccelerator      重启服务


压力测试