www.gusucode.com > ShopEx481 & PHPWind 整合版码程序 > plugins/functions/memcached.php

    <?php
/*
 * 使用memcached作为系统缓存。
 * 使用方法: 添加以下内容到你的config.php中
 *     define('CACHE_METHOD','memcached');
 *     define('MEMCACHED_HOST',你的memcache服务器ip);
 *     define('MEMCACHED_PORT',memcache服务器端口);
 */

class memcached{

	var $name='Memcache';
	var $desc='Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.';

	function memcached(){
		$this->obj = new Memcache;
		if(!$this->obj->connect(MEMCACHED_HOST, MEMCACHED_PORT)){
			trigger_error('Can\'t connect memcached server',E_USER_ERROR);
		}
	}

	function store($key,&$value,$ttl=null){
		$this->obj->set($key,$value);
	}

	function &fetch($key){
		return $obj = $this->obj->get($key);
	}

	function clear(){
		return $this->obj->flush();
	}

	function status(&$curBytes,&$totalBytes){

		$curBytes = $info['bytes'];
		$totalBytes = $info['limit_maxbytes'];

		$info = $this->obj->getStats();
		$return[] = array('name'=>'子系统运行时间','value'=>timeLength($info['uptime']));
		$return[] = array('name'=>'缓存服务器','value'=>MEMCACHED_HOST.':'.MEMCACHED_PORT." (ver:{$info['version']})");
		$return[] = array('name'=>'数据读取','value'=>$info['cmd_get'].'次 '.formatBytes($info['bytes_written']));
		$return[] = array('name'=>'数据写入','value'=>$info['cmd_set'].'次 '.formatBytes($info['bytes_read']));
		$return[] = array('name'=>'缓存命中','value'=>$info['get_hits'].'次');
		$return[] = array('name'=>'缓存未命中','value'=>$info['get_misses'].'次');
		$return[] = array('name'=>'已缓存数据条数','value'=>$info['curr_items'].'条');
		$return[] = array('name'=>'进程数','value'=>$info['threads']);
		$return[] = array('value'=>$info['pid'],'name'=>'服务器进程ID');
		$return[] = array('value'=>$info['rusage_user'],'name'=>'该进程累计的用户时间(秒:微妙)');
		$return[] = array('value'=>$info['rusage_system'],'name'=>'该进程累计的系统时间(秒:微妙)');
		$return[] = array('value'=>$info['curr_items'],'name'=>'服务器当前存储的内容数量');
		$return[] = array('value'=>$info['total_items'],'name'=>'服务器启动以来存储过的内容总数');

//    $return[] = array('value'=>$info['curr_connections'],'name'=>'连接数量');
//    $return[] = array('value'=>$info['total_connections'],'name'=>'服务器运行以来接受的连接总数 ');
//    $return[] = array('value'=>$info['connection_structures'],'name'=>'服务器分配的连接结构的数量');
		return $return;
	}

}
?>