xcache的安装

2012年4月22日 发表评论 阅读评论

      原来弄好的LNMP环境,因为php版本太新,而原来使用的eAccelerator因为很久没有更新了,所以无法支持php的新版本。所以想到使用xcache来进行php的加速。

      首先我用到的是XCache 2.0.0,可以支持最新的php 5.4。

wget http://xcache.lighttpd.net/pub/Releases/2.0.0/xcache-2.0.0.tar.gz
tar -zxvf xcache-2.0.0.tar.gz
cd xcache-2.0.0
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make
make test

   不过在安装的时候遇到了下面的问题:

+------------------------------------------------------------------------+

|                       ! ERROR !                                         |

| The test-suite requires that proc_open() is available.    |

| Please check if you disabled it in php.ini.                     |

+---------------------------------------------------------------------+

通过上面的提示,不难发现是因为我在php的安全设置中禁用了proc_open函数的调用。我在php.ini中禁用的调用函数如下:

 

disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,ini_alter,proc_open,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen

在取消了proc_open函数的调用后,再进行make test的过程中,发现还有下面的报错:

PHP Warning:  shell_exec() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 284
PHP Warning:  shell_exec() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 285
PHP Warning:  shell_exec() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 299
=====================================================================
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PASS include absolute path [tests/xcache_include_absolute.phpt]
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PASS include relative to current working dir [tests/xcache_include_relative_cwd.phpt]
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PASS include relative to current file [tests/xcache_include_relative_file.phpt]
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
PASS xcache_is_autoglobal [tests/xcache_is_autoglobal.phpt]
PHP Warning:  proc_get_status() has been disabled for security reasons in /usr/local/src/site/xcache-2.0.0/run-tests.php on line 1128
FAIL xcache_set/get test [tests/xcache_var.phpt]
=====================================================================

    该问题是因为另外两个函数shell_exec、proc_get_status也被禁用了 ,于是把这两个函数的禁用也取消了。再重新make test的时候发现还是有一项测试未通过:

FAIL xcache_set/get test [tests/xcache_var.phpt]

无奈之下,换成老版本的XCache 1.3.2进行测试。测试通过,接着make install安成安装。

完成后,提示生成了xcache.so在/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/目录下。接着在php.ini中加入下面的内容(具体可以参看xcache安装包中的xcache.ini文件并进行修改):

[xcache-common]
zend_extension      = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user   = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass   = "8a488a9ed9dc3634f70b421b06d835e5"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size         = 64M
xcache.shm_scheme   = "mmap"
xcache.count        = 2
xcache.slots        = 8K
xcache.ttl          = 0
xcache.gc_interval  = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size     = 8M
xcache.var_count    = 4
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    = Off

 接着重新加载nginx,配置生效。发现速度确实快了很多。

上面一些主要参数的介绍如下:

xcache.admin.enable_auth  XCache后台是否需要验证(这个后台在刚才下载的XCache的admin目录中,可以自由处理)

xcache.admin.user XCache后台登陆用户名

xcache.admin.pass XCache后台登陆密码

xcache.size   XCache的内存缓存大小,普通网站建议设置为64MB,如果是IDC服务器,可以设置成256MB

xcache.count  设置为CPU的数量(双核算2个,比如我的是两个双核Xeon 3.0,就设置为4)

xcache.var_size

xcache.var_count  跟上两条一样

xcache.mmap_path  共享内存标识名,尽量用xcache,避免跟其它软件冲突

xcache.optimizer  优化器,如果没安装Zend可以开启。

    需要进入web管理界面的,还需要把安装目录下的admin目录复制到站点的相应访问目录,并用上面设置的用户名密码访问即可。

以上内容为本人自己总结,主要参考下面几个站点的页面:

http://zlnet.net/blog/?p=923

http://www.ibm.com/developerworks/cn/opensource/os-php-fastapps1/

http://hi.baidu.com/binarie/blog/item/619ccf0efedd19e336d122bd.html

 




本站的发展离不开您的资助,金额随意,欢迎来赏!

You can donate through PayPal.
My paypal id: itybku@139.com
Paypal page: https://www.paypal.me/361way

分类: http/html/web 标签:
  1. 本文目前尚无任何评论.