| 
						 
							1
						 
						
							2
						 
						
							3
						 
						
							4
						 
						
							5
						 
						
							6
						 
						
							7
						 
						
							8
						 
						
							9
						 
						
							10
						 
						
							11
						 
						
							12
						 
						
							13
						 
						
							14
						 
						
							15
						 
						
							16
						 
						
							17
						 
						
							18
						 
						
							19
						 
						
							20
						 
						
							21
						 
						
							22
						 
						
							23
						 
						
							24
						 
						
							25
						 
						
							26
						 
						
							27
						 
						
							28
						 
						
							29
						 
						
							30
						 
						
							31
						 
						
							32
						 
						
							33
						 
						
							34
						 
						
							35
						 
						
							36
						 
						
							37
						 
						
							38
						 
						
							39
						 
						
							40
						 
						
							41
						 
						
							42
						 
						
							43
						 
						
							44
						 
						
							45
						 
						
							46
						 
						
							47
						 
						
							48
						 
						
							49
						 
						
							50
						 
						
							51
						 
						
							52
						 
						
							53
						 
						
							54
						 
						
							55
						 
						
							56
						 
						
							57
						 
						
							58
						 
						
							59
						 
						
							60
						 
						
							61
						 
						
							62
						 
						
							63
						 
						
							64
						 
						
							65
						 
						
							66
						 
						
							67
						 
						
							68
						 
						
							69
						 
						
							70
						 
						
							71
						 
						
							72
						 
						
							73
						 
						
							74
						 
						
							75
						 
						
							76
						 
						
							77
						 
						
							78
						 
						
							79
						 
						
							80
						 
						
							81
						 
						
							82
						 
						
							83
						 
						
							84
						 
						
							85
						 
						
							86
						 
						
							87
						 
						
							88
						 
						
							89
						 
						
							90
						 
						
							91
						 
						
							92
						 
						
							93
						 
						
							94
						 
						
							95
						 
						
							96
						 
						
							97
						 
						
							98
						 
						
							99
						 
						
							100
						 
						
							101
						 
						
							102
						 
						
							103
						 
						
							104
						 
						
							105
						 
						
							106
						 
						
							107
						 
						
							108
						 
						
							109
						 
						
							110
						 
						
							111
						 
						
							112
						 
						
							113
						 
						
							114
						 
						
							115
						 
						
							116
						 
						
							117
						 
						
							118
						 
						
							119
						 
						
							120
						 
						
							121
						 
						
							122
						 
						
							123
						 
						
							124
						 
						
							125
						 
						
							126
						 
						
							127
						 
					 | 
					
						 
								<?php
							 
							
								/**
							 
							
								 * Memcache<a href="http://www.php1.cn/category/79.html">缓存</a>操作
							 
							
								 * @update http://www.lai18.com
							 
							
								 */
							 
							
								classMCacheextendsObjectimplementsCacheFace
							 
							
								{
							 
							
								  private$mem= null;//Mem对象
							 
							
								  private$sId= 1; //servier服务ID
							 
							
								  /**
							 
							
								   * 初始化Memcache
							 
							
								   *
							 
							
								   * @return Object
							 
							
								   */
							 
							
								  publicfunction__construct()
							 
							
								  {
							 
							
								    if( !class_exists('Memcache') )
							 
							
								    {
							 
							
								      thrownewQException('PHP extension does not exist: Memcache');
							 
							
								    }
							 
							
								    $this->mem =newMemcache();
							 
							
								  }
							 
							
								  /**
							 
							
								   * 链接memcahce服务
							 
							
								   *
							 
							
								   * @access private
							 
							
								   * @param  string $key 关键字
							 
							
								   * @param  string $value <a href="http://www.php1.cn/category/79.html">缓存</a>内容
							 
							
								   * @return array
							 
							
								   * @update http://www.lai18.com
							 
							
								   */
							 
							
								  privatefunctionconnect($sid)
							 
							
								  {
							 
							
								    $file=$this->CacheFile();
							 
							
								    require$file;
							 
							
								    if(! isset($cache) )
							 
							
								    {
							 
							
								      thrownewQException('<a href="http://www.php1.cn/category/79.html">缓存</a>配置文件不存在'.$file);
							 
							
								    }
							 
							
								    $server=$cache[$this->cacheId];
							 
							
								    $sid = isset($sid) == 0 ?$this->sId :$sid;//memcache服务选择
							 
							
								    if( !$server[$sid])
							 
							
								    {
							 
							
								      thrownewQException('当前操作的<a href="http://www.php1.cn/category/79.html">缓存</a>服务器配置文件不存在');
							 
							
								    }
							 
							
								    $host=$server[$sid]['host'];
							 
							
								    $port=$server[$sid]['port'];
							 
							
								    try{
							 
							
								      $this->mem->connect($host,$port);
							 
							
								    }catch(Exception$e) {
							 
							
								      exit('memecache连接失败,错误信息:'.$e->getMessage());
							 
							
								    }
							 
							
								  }
							 
							
								  /**
							 
							
								   * 写入<a href="http://www.php1.cn/category/79.html">缓存</a>
							 
							
								   *
							 
							
								   * @access private
							 
							
								   * @param  string $key 关键字
							 
							
								   * @param  string $value <a href="http://www.php1.cn/category/79.html">缓存</a>内容
							 
							
								   * @return array
							 
							
								   */
							 
							
								  publicfunctionset($key,$value,$sid,$expire= 0)
							 
							
								  {
							 
							
								    $data=$this->get($key,$sid);//如果已经存在key值
							 
							
								    if($data)
							 
							
								    {
							 
							
								      return$this->mem->set($key,$value,MEMCACHE_COMPRESSED ,$expire);
							 
							
								    }else{
							 
							
								      return$this->mem->add($key,$value,MEMCACHE_COMPRESSED ,$expire);
							 
							
								    }
							 
							
								  }
							 
							
								  /**
							 
							
								   * 读取<a href="http://www.php1.cn/category/79.html">缓存</a>
							 
							
								   *
							 
							
								   * @access private
							 
							
								   * @param  string $key 关键字
							 
							
								   * @param  int   $sid 选择第几台memcache服务器
							 
							
								   * @return array
							 
							
								   */
							 
							
								  publicfunctionget($key,$sid)
							 
							
								  {
							 
							
								    $this->connect($sid);
							 
							
								    return$this->mem->get($key);
							 
							
								  }
							 
							
								  /**
							 
							
								   * 清洗(删除)已经存储的所有的元素
							 
							
								   *
							 
							
								   * @access private
							 
							
								   * @return array
							 
							
								   */
							 
							
								  publicfunctionflush()
							 
							
								  {
							 
							
								    $this->connect();
							 
							
								    return$this->mem->flush();
							 
							
								  }
							 
							
								  /**
							 
							
								   * 删除<a href="http://www.php1.cn/category/79.html">缓存</a>
							 
							
								   *
							 
							
								   * @access private
							 
							
								   * @param  string $key 关键字
							 
							
								   * @param  int   $sid 选择第几台memcache服务器
							 
							
								   * @return array
							 
							
								   */
							 
							
								  publicfunctionremove($key,$sid)
							 
							
								  {
							 
							
								    $this->connect();
							 
							
								    return$this->mem->delete($key);
							 
							
								  }
							 
							
								  /**
							 
							
								   * 析构函数
							 
							
								   * 最后关闭memcache
							 
							
								   */
							 
							
								  publicfunction__destruct()
							 
							
								  {
							 
							
								    /*if(! $this->mem)
							 
							
								    {
							 
							
								      $this->mem->close();
							 
							
								    }*/
							 
							
								  }
							 
							
								}
							 
						 | 
				
哈尔滨品用软件有限公司致力于为哈尔滨的中小企业制作大气、美观的优秀网站,并且能够搭建符合百度排名规范的网站基底,使您的网站无需额外费用,即可稳步提升排名至首页。欢迎体验最佳的哈尔滨网站建设。
