手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

FreeBSD安装配置Xcache

[日期:2012-06-19] 来源:Linux社区  作者:webteam [字体: ]

朋友要做用MediaWiki做网站,用的是Mediawiki1.18.4,安装过程中提示系统需要配置缓存插件,比如eaccelerator、apc或者xcache,之前我一直用apc,不知道为什么这次安装过程中apc和我的php版本不兼容,无奈只好选择Xcache,网上搜索了一些资料,谈到Xcache是由华人开发的,效率很高,并且维护的比较好。

下面一段摘自百度百科:

XCache 是一个开源的 opcode 缓存器/优化器, 这意味着他能够提高您服务器上的 PHP 性能. 他通过把编译 PHP 后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接使用缓冲区已编译的代码从而提高速度. 通常能够提高您的页面生成速率 2 到5 倍, 降低服务器负载.

Xcache的安装非常简单,安装之后需要稍做配置,下面梳理一下我安装使用的步骤: 

一、Ports安装

  1. cd /usr/ports/www/xcache/; make install clean 

安装完成之后要进行设定,设定的例子放在 /usr/local/share/examples/xcache/,里面也包含了xcache 的管理界面。

 

二、配置文件

  1. cp /usr/local/share/examples/xcache/xcache.ini /usr/local/etc/php/ 

拷贝xcache.ini文件到/usr/local/etc/php/文件夹下,打开xcache.ini:

 

  1. [xcache-common] 
  2. ;; install as zend extension (recommended, but not working yet) 
  3. zend_extension = /usr/local/lib/php/20060613/xcache.so 
  4. zend_extension_ts = /usr/local/lib/php/20060613/xcache.so 
  5. ;; or install as extension 
  6. extension = xcache.so 
  7.  
  8. [xcache.admin] 
  9. xcache.admin.enable_auth = On 
  10. xcache.admin.user = "admin" //管理用户名
  11. xcache.admin.pass = md5($your_password) //这一行可以不要
  12. xcache.admin.pass = "******" // 这个是你的密码进行md5加密后的串
  13.  
  14. [xcache] 
  15. ; ini only settings, all the values here is default unless explained 
  16.  
  17. ; select low level shm/allocator scheme implemenation 
  18. xcache.shm_scheme =        "mmap" 
  19. ; to disable: xcache.size=0 
  20. ; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows 
  21. xcache.size  =               60M 
  22. ; set to cpu count (cat /proc/cpuinfo |grep -c processor) 
  23. xcache.count =                 1 
  24. ; just a hash hints, you can always store count(items) > slots 
  25. xcache.slots =                8K 
  26. ; ttl of the cache item, 0=forever 
  27. xcache.ttl   =                 0 
  28. ; interval of gc scanning expired items, 0=no scan, other values is in seconds 
  29. xcache.gc_interval =           0 
  30.  
  31. ; same as aboves but for variable cache 
  32. xcache.var_size  =            256M  //可以根据实际情况进行调整,我之前4M程序就报错
  33. xcache.var_count =             1 
  34. xcache.var_slots =            8K 
  35. ; default ttl 
  36. xcache.var_ttl   =             0 
  37. xcache.var_maxttl   =          0 
  38. xcache.var_gc_interval =     300 
  39.  
  40. xcache.test =                Off 
  41. ; N/A for /dev/zero 
  42. xcache.readonly_protection = Off 
  43. ; for *nix, xcache.mmap_path is a file path, not directory. 
  44. ; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection 
  45. ; 2 group of php won't share the same /tmp/xcache 
  46. ; for win32, xcache.mmap_path=anonymous map name, not file path 
  47. xcache.mmap_path =    "/tmp/xcache" //xcache这是个一个文件,不是文件夹
  48.  
  49.  
  50. ; leave it blank(disabled) or "/tmp/phpcore/" 
  51. ; make sure it's writable by php (without checking open_basedir) 
  52. xcache.coredump_directory =   "" 
  53.  
  54. ; per request settings 
  55. xcache.cacher =               On 
  56. xcache.stat   =               On 
  57. xcache.optimizer =           Off 
  58.  
  59. [xcache.coverager] 
  60. ; per request settings 
  61. ; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance) 
  62. xcache.coverager =          Off 
  63.  
  64. ; ini only settings 
  65. ; make sure it's readable (care open_basedir) by coverage viewer script 
  66. ; requires xcache.coverager=On 
  67. xcache.coveragedump_directory = "" 

这个文件需要修改的不多,只需要改用户,密码(php,md5生成),xcache.var_size,xcache.mmap_path这几个地方;

设置好之后,需要到tmp目录下建立xcache文件,不是目录哦

  1. touch /tmp/cache && chmod 777 /tmp/cache 

完成之后,就可以重启web服务器了,appache或者nginx;查看xcache是否生效可以通过phpinfo函数查看,或者用php -v 也可以看到:

  1. PHP 5.2.17 with Suhosin-Patch 0.9.7 (cli) (built: May 31 2012 17:26:19) 
  2. Copyright (c) 1997-2009 The PHP Group 
  3. Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies 
  4. with XCache v1.3.2, Copyright (c) 2005-2011, by mOo 
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款