Example #1
0
 /**
  * 获取MemCache缓存
  * 可被重写
  * @return mixed
  */
 public function get($cacheParam = null)
 {
     if ($cacheParam !== null && $this->_cacheParam !== $cacheParam) {
         $this->processParam($cacheParam);
     }
     #返回缓存数据
     if (!empty($this->_cachePool[$this->_cacheKey])) {
         return $this->_cachePool[$this->_cacheKey];
     }
     $modName = $this->_moduleName;
     $modName .= $this->_hash ? '.' . $this->_cacheKey[0] : '';
     $data = ZOL_Caching_Mongo::get($modName, $this->_cacheKey, false, $this->_mongoServerKey, 0, $this->_mongoDbName);
     #添加日志功能
     if (IS_DEBUGGING) {
         $nowTime = date("H:i:s");
         $nowUrl = str_replace("_check_mongo_read=", "", $_SERVER["REQUEST_URI"]);
         $logContent = "{$nowUrl} [{$nowTime}] CacheRead:{$modName} Param:" . json_encode($cacheParam) . "\n";
         ZOL_Log::checkUriAndWrite(array('message' => $logContent, 'paramName' => '_check_mongo_read'));
     }
     if (isset($data['date']) && isset($data['exprieTime'])) {
         $nowTime = date("Y-m-d H:i:s");
         $expreTime = strtotime($nowTime) - strtotime($data['date']);
         if ($expreTime >= $data['exprieTime']) {
             $data = false;
         }
     }
     if (!$data && $this->_autoRefresh && $this->refresh($this->_cacheParam)) {
         #自动更新缓存
         $data = $this->_content;
     }
     $this->_cachePool[$this->_cacheKey] = $data;
     return $data;
 }
Example #2
0
 /**
  * 查询
  * 
  * @param string $sql
  * @return PDOStatement
  */
 public function query($sql = '')
 {
     static $reconnectNum = 0;
     #添加日志功能,重置时间
     if (IS_DEBUGGING) {
         ZOL_Log::resetTime();
     }
     $this->chooseDbConn($sql);
     $sql .= $this->sqlComment;
     $query = $this->db->query($sql);
     if (empty($query)) {
         $error = $this->errorInfo();
         if ($reconnectNum < 5 && $error[0] == 'HY000') {
             $this->db = null;
             $reconnectNum++;
             if ($reconnectNum > 1) {
                 sleep($reconnectNum);
             }
             return $this->query($sql);
         }
         trigger_error($error[2], E_USER_WARNING);
     }
     $reconnectNum = 0;
     #添加日志功能
     if (IS_DEBUGGING && isset($_SERVER["REQUEST_URI"])) {
         $nowTime = date("H:i:s");
         $nowUrl = str_replace("_check_mysql_query=", "", $_SERVER["REQUEST_URI"]);
         $sql = str_replace("\n", "", $sql);
         $sql = preg_replace("#\\s{2,}#", " ", $sql);
         $logContent = "{$nowUrl} [{$nowTime}][" . $this->servers['slave']['host'] . " - " . $this->servers['slave']['database'] . "] SQL:" . $sql . " \n";
         ZOL_Log::checkUriAndWrite(array('message' => $logContent, 'paramName' => '_check_mysql_query', 'recTime' => true));
     }
     return $query;
 }