/** * 获取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; }
protected static function init($mongoServerKey = 0, $isMongoWrite = 0) { static $reconn = 0; static $faildServer = null; $mongoKey = self::$_mongoServerKey . $mongoServerKey . $isMongoWrite; if (empty(self::$mongo[$mongoKey])) { defined('MONGOCACHE_CONF_KEY') || define('MONGOCACHE_CONF_KEY', 'Mongo'); $memConf = ZOL_Config::get(MONGOCACHE_CONF_KEY); if ($memConf) { self::$server = $memConf; } try { if ($mongoServerKey) { if (self::$mongoDbArr[$mongoServerKey]) { if ($isMongoWrite) { self::$server = self::$mongoDbArr[$mongoServerKey]['wserver']; self::$eserver = self::$mongoDbArr[$mongoServerKey]['wserver']; } else { self::$server = self::$mongoDbArr[$mongoServerKey]['server']; self::$eserver = self::$mongoDbArr[$mongoServerKey]['eserver']; } } } else { self::$server = 'localhost'; self::$eserver = 'mongo_server_zoldb'; //均衡服务器 } if ($reconn == 0) { $server = self::$server; } else { $server = self::$eserver; } $server = 'mongodb://' . $server; self::$mongo[$mongoKey] = new Mongo($server, array('timeout' => self::$timeout, 'persist' => 'Product')); } catch (MongoException $e) { if (self::$mongo[$mongoKey]) { self::$mongo[$mongoKey]->close(); } self::$mongo[$mongoKey] = null; if ($reconn < 2) { ++$reconn; return self::init($mongoServerKey, $isMongoWrite); } ZOL_Log::write('异常1:' . $e->getMessage(), ZOL_Log::TYPE_ERROR); Plugin_Expires::setExpires(0); ZOL_Http::sendHeader(404); trigger_error($e->getMessage(), E_USER_WARNING); exit; } } $reconn = 0; }
public static function handler($exception) { if ($exception instanceof Exception) { $debugging = defined('IS_DEBUGGING') ? IS_DEBUGGING : false; $production = defined('IS_PRODUCTION') ? IS_PRODUCTION : false; if (true == $debugging) { if (true == $production) { ZOL_Log::write(ZOL_String::clean($exception), ZOL_Log::TYPE_EXCEPTION); } else { echo ZOL_Request::resolveType() == ZOL_Request::CLI ? ZOL_String::clean($exception) : $exception; } } else { header('location: ' . SYSTEM_HOMEPAGE); } } }
public static function handler($level, $errorMsg, $file, $line, $context = null) { if ('.tpl.php' == substr($file, -8)) { return; } $str = new ZOL_Exception($errorMsg, $level, $file, $line); $debugging = IS_DEBUGGING; $production = IS_PRODUCTION; if ($debugging) { $content = "<br />\n<h2>Error Info:</h2>\n" . '<b>MESSAGE:</b> ' . $errorMsg . "<br />\n" . '<b>TYPE:</b> ' . (isset(self::$levels[$level]) ? self::$levels[$level] : $level) . "<br />\n" . '<b>FILE:</b> ' . $file . "<br />\n" . '<b>LINE:</b> ' . $line . "<br />\n" . $str; if ($production) { ZOL_Log::write(ZOL_String::clean($content), ZOL_Log::TYPE_ERROR); } else { echo ZOL_Request::resolveType() == ZOL_Request::CLI ? ZOL_String::clean($content) : $content; } } }
/** * 查询 * * @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 < 3 && $error[0] == 'HY000' && in_array($error[1], array(2003, 2004, 2006, 2055, 2013))) { $this->db = null; $reconnectNum++; if ($reconnectNum > 1) { usleep(50000); } return $this->query($sql); } trigger_error($error[2], E_USER_WARNING); } $reconnectNum = 0; #添加日志功能 /* if(IS_DEBUGGING){ $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; }
/** * 重设时间,为了统计某一个执行的时间用 */ public static function resetTime() { self::$timer = microtime(true); }