使用Xcache缓存器加速PHP网站的配置方法

时间:2021-05-25

推荐地址:http://mon]extension = xcache.so[xcache.admin]xcache.admin.enable_auth = Onxcache.admin.user = "xcache"xcache.admin.pass = ""[xcache]xcache.shm_scheme ="mmap"xcache.size=60Mxcache.count =1xcache.slots =8Kxcache.ttl=0xcache.gc_interval =0xcache.var_size=4Mxcache.var_count =1xcache.var_slots =8Kxcache.var_ttl=0xcache.var_maxttl=0xcache.var_gc_interval =300xcache.test =Offxcache.readonly_protection = Onxcache.mmap_path ="/tmp/xcache"xcache.coredump_directory =""xcache.cacher =Onxcache.stat=Onxcache.optimizer =Off[xcache.coverager]xcache.coverager =Onxcache.coveragedump_directory =""

2、生成Xcache缓存文件

# touch /tmp/xcache# chmod 777 /tmp/xcache

3、生成Xcache管理员的秘密(MD5密文)

# echo -n "123456" |

md5sume10adc3949ba59abbe56e057f20f883e

  然后将上述生成的MD5密文粘贴到php.ini文件中xcache.admin.pass = ""选项,xcache.admin.pass= "e10adc3949ba59abbe56e057f20f883e"

4、拷贝Xcache管理程序到网站根目录下

# cp -a /tmp/xcache-1.3.0/admin//usr/local/nginx/html/

  然后重新启动PHP,然后访问http://localhost/admin ,用户名为xcache 密码为123456;另外,还可以通过phpinfo来验证PHP是否支持Xcache

这里要注意的一点就是Xcache只能缓存默认的一些对象,如int, string, array等,不能缓存对象,否则读取的时候就会报错。

  如果你非要缓存对象的话也有办法就是将对象序列化,读取的时候再反序列化一次。

  下面我写的一个Xcache的简单类:

程序代码

<?php/*** Xcache moudle*/class cacheHelper{  public $prefix;  function __construct(){    if(!function_exists('xcache_get')){      exit("This application must required XCache module.");    }  }  /**   * __set   *   * @param mixed $name   * @param mixed $value   * @access public   * @return void   */  public function __set($name, $value){    xcache_set($this->prefix.$name, $value);  }  /**   * __get   *   * @param mixed $name   * @access public   * @return mixed   */  public function __get($name){    return xcache_get($this->prefix.$name);  }  /**   * __isset   *   * @param mixed $name   * @access public   * @return bool   */  public function __isset($name){    return xcache_isset($this->prefix.$name);  }  /**   * __unset   *   * @param mixed $name   * @access public   * @return void   */  public function __unset($name){    xcache_unset($this->prefix.$name);  }}?>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章