Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * 删除MemCache缓存
  */
 public function rm($cacheParam = null)
 {
     if (isset($cacheParam) && $this->_cacheParam != $cacheParam) {
         $this->processParam($cacheParam);
     }
     if (empty($this->_cacheKey)) {
         return false;
     }
     $modName = $this->_moduleName;
     $modName .= $this->_hash ? '.' . $this->_cacheKey[0] : '';
     return ZOL_Caching_Mongo::delete($modName, $this->_cacheKey, $this->_mongoServerKey, 1, $this->_mongoDbName);
 }