當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Memcache::setOptions方法代碼示例

本文整理匯總了PHP中Memcache::setOptions方法的典型用法代碼示例。如果您正苦於以下問題:PHP Memcache::setOptions方法的具體用法?PHP Memcache::setOptions怎麽用?PHP Memcache::setOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Memcache的用法示例。


在下文中一共展示了Memcache::setOptions方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _init

 /**
  * Do initialization.
  *
  * @throws Horde_Memcache_Exception
  */
 public function _init()
 {
     if (class_exists('Memcached')) {
         if (empty($this->_params['persistent'])) {
             $this->_memcache = new Memcached();
         } else {
             $this->_memcache = new Memcached('horde_memcache');
         }
         $this->_params['large_items'] = false;
         $this->_memcache->setOptions(array(Memcached::OPT_COMPRESSION => $this->_params['compression'], Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT, Memcached::OPT_HASH => Memcached::HASH_MD5, Memcached::OPT_LIBKETAMA_COMPATIBLE => true, Memcached::OPT_PREFIX_KEY => $this->_params['prefix']));
     } else {
         // Force consistent hashing
         ini_set('memcache.hash_strategy', 'consistent');
         $this->_memcache = new Memcache();
     }
     for ($i = 0, $n = count($this->_params['hostspec']); $i < $n; ++$i) {
         if ($this->_memcache instanceof Memcached) {
             $res = $this->_memcache->addServer($this->_params['hostspec'][$i], empty($this->_params['port'][$i]) ? 0 : $this->_params['port'][$i], !empty($this->_params['weight'][$i]) ? $this->_params['weight'][$i] : 0);
         } else {
             $res = $this->_memcache->addServer($this->_params['hostspec'][$i], empty($this->_params['port'][$i]) ? 0 : $this->_params['port'][$i], !empty($this->_params['persistent']), !empty($this->_params['weight'][$i]) ? $this->_params['weight'][$i] : 1, 1, 15, true, array($this, 'failover'));
         }
         if ($res) {
             $this->_servers[] = $this->_params['hostspec'][$i] . (!empty($this->_params['port'][$i]) ? ':' . $this->_params['port'][$i] : '');
         }
     }
     /* Check if any of the connections worked. */
     if (empty($this->_servers)) {
         throw new Horde_Memcache_Exception('Could not connect to any defined memcache servers.');
     }
     if ($this->_memcache instanceof Memcache && !empty($this->_params['c_threshold'])) {
         $this->_memcache->setCompressThreshold($this->_params['c_threshold']);
     }
     if (isset($this->_params['logger'])) {
         $this->_logger = $this->_params['logger'];
         $this->_logger->log('Connected to the following memcache servers:' . implode($this->_servers, ', '), 'DEBUG');
     }
 }
開發者ID:horde,項目名稱:horde,代碼行數:42,代碼來源:Memcache.php


注:本文中的Memcache::setOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。