【php开源代码栏目提醒】:网学会员--在 php开源代码编辑为广大网友搜集整理了:CacheApachenote.class.php绩等信息,祝愿广大网友取得需要的信息,参考学习。
<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <
CacheApachenote.class.php为[网学网-网友上传,谢谢支持]。>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* Apachenote缂撳瓨绫?
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <
CacheApachenote.class.php为[网学网-网友上传,谢谢支持]。>
* @version $Id$
+------------------------------------------------------------------------------
*/
class CacheApachenote extends Cache
{//绫诲畾涔夊紑濮?
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function __construct($options='')
{
if(empty($options)){
$options = array(
'host' => '127.0.0.1',
'port' => 1042,
'timeout' => 10
);
}
$this->handler = null;
$this->open();
$this->options = $options;
$this->type = strtoupper(substr(__CLASS__,6));
}
/**
+----------------------------------------------------------
* 鏄惁杩炴帴
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function isConnected()
{
return $this->connected;
}
/**
+----------------------------------------------------------
* 璇诲彇缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function get($name)
{
$this->open();
$s = 'F' . pack('N', strlen($name)) . $name;
fwrite($this->handler, $s);
for ($data = ''; !feof($this->handler);) {
$data .= fread($this->handler, 4096);
}
$this->Q(1);
$this->close();
return $data === '' ? '' : unserialize($data);
}
/**
+----------------------------------------------------------
* 鍐欏叆缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
* @param mixed $value 瀛樺偍鏁版嵁
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value)
{
$this->W(1);
$this->open();
$value = serialize($value);
$s = 'S' . pack('NN', strlen($name), strlen($value)) . $name . $value;
fwrite($this->handler, $s);
$ret = fgets($this->handler);
$this->close();
$this->setTime[$name] = time();
return $ret === "OK\n";
}
/**
+----------------------------------------------------------
* 鍒犻櫎缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function rm($name)
{
$this->open();
$s = 'D' . pack('N', strlen($name)) . $name;
fwrite($this->handler, $s);
$ret = fgets($this->handler);
$this->close();
return $ret === "OK\n";
}
/**
+----------------------------------------------------------
* 鍏抽棴缂撳瓨
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
*/
private function close()
{
fclose($this->handler);
$this->handler = false;
}
/**
+----------------------------------------------------------
* 鎵撳紑缂撳瓨
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
*/
private function open()
{
if (!is_resource($this->handler)) {
$this->handler = fsockopen($this->options['host'], $this->options['port'], $_, $_, $this->options['timeout']);
$this->connected = is_resource($this->handler);
}
}
}//绫诲畾涔夌粨鏉?
?>
上一篇:
cache.php
下一篇:
扛起年轻化大旗,哈弗F系玩转行业新风潮