XCache

安装XCache模块
  # phpize
  # ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache --enable-xcache-optimizer
  # make
  # make install
  算出密码的MD5字串
  # echo -n “123456″ | md5sum
  配置XCache
  # vi /etc/php.ini
  [xcache-common]
  zend_extension = /usr/local/php/lib/php/extensions/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 = "e10adc3949ba59abbe56e057f20f883e"
  [xcache]
  ; Change xcache.size to tune the size of the opcode cache
  xcache.size = 24M
  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 = 1
  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]
  xcache.coverager = On
  xcache.coveragedump_directory = ""

  

示例代码:

<?php
define(TMPDIR, '/tmp');

function load_abc_data()
{
  if (xcache_isset("abc_data")) {
    return xcache_get("abc_data");
  }
  // it worth a lock here to avoid useless yet harmful concurrent 
// load from any slow backend (backend=mysql here).
$fp = fopen(TMPDIR . "/abc_data.lock", "w"); flock($fp, LOCK_EX); // check AGAIN after we get the lock if (xcache_isset("abc_data")) { fclose($fp); return xcache_get("abc_data"); } mysql_query .... and get $data xcache_set("abc_data", $data, 120); // save for 2 minutes fclose($fp); return $data; } ?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值