当前位置: 首页>>代码示例>>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;未经允许,请勿转载。