Пример #1
0
 /**
  * 读取SESSION内容
  *
  * @param string $sid 会话唯一标识
  * @return string 会话值
  */
 public function read($sid)
 {
     /**
      * 以数据库方式来处理SESSION
      */
     if ($this->_type == 'db' || $this->_type == 'mdb') {
         $res = $this->_db->fetch_row("SELECT sData FROM {$this->_opt} WHERE sId = '{$sid}';");
         return $res ? $res['sData'] : '';
     }
     /**
      * 以Memcache缓冲方式来处理SESSION
      */
     if ($this->_type == 'mem') {
         return $this->_mem->get('session', $sid);
     }
     /**
      * 以文件系统的方式来处理SESSION
      */
     if ($this->_type == 'dir') {
         $sfile = "{$this->_path}/{$sid[0]}/{$this->_prefix}-{$sid}";
     } else {
         $sfile = "{$this->_path}/{$this->_prefix}-{$sid}";
     }
     if (!file_exists($sfile)) {
         return '';
     }
     return (string) file_get_contents($sfile);
 }
Пример #2
0
 /**
  * hash数组,将数组中的某个字段值索引成数组的KEY
  *
  * @param array  $arr         需要HASH的数组
  * @param string $key         要定的数组字段名
  * @param array  $mem_type    需要HASH的数组
  * @param int    $expire      有效期以分钟为单位,为0时则永不过期只有当MEM服务器关闭才过期
  * @return array|mixed 返回数据
  */
 public function &mem_hash($arr, $key, $mem_type, $expire = 30)
 {
     if (empty($arr) || !is_array($arr)) {
         return $arr;
     }
     $mem_type = "{$mem_type}-{$key}";
     $res = $this->mem->get(__FUNCTION__, $mem_type);
     if (!empty($res)) {
         return $res;
     }
     /**
      * 将数据进行hash
      */
     $res = array();
     foreach ($arr as $v) {
         if (isset($v[$key])) {
             $res[$v[$key]] = $v;
         }
     }
     /**
      * 存储数据并返回数据
      */
     $this->mem->set(__FUNCTION__, $mem_type, $res, $expire);
     return $res;
 }