当前位置: 首页>>代码示例>>PHP>>正文


PHP Memcache::setOption方法代码示例

本文整理汇总了PHP中Memcache::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::setOption方法的具体用法?PHP Memcache::setOption怎么用?PHP Memcache::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Memcache的用法示例。


在下文中一共展示了Memcache::setOption方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _setOptions

/**
 * Settings the memcached instance
 *
 * @throws CacheException when the Memcached extension is not built with the desired serializer engine
 * @return void
 */
	protected function _setOptions() {
		$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);

		$serializer = strtolower($this->settings['serialize']);
		if (!isset($this->_serializers[$serializer])) {
			throw new CacheException(
				__d('cake_dev', '%s is not a valid serializer engine for Memcached', $serializer)
			);
		}

		if ($serializer !== 'php' && !constant('Memcached::HAVE_' . strtoupper($serializer))) {
			throw new CacheException(
				__d('cake_dev', 'Memcached extension is not compiled with %s support', $serializer)
			);
		}

		$this->_Memcached->setOption(Memcached::OPT_SERIALIZER, $this->_serializers[$serializer]);

		// Check for Amazon ElastiCache instance
		if (defined('Memcached::OPT_CLIENT_MODE') && defined('Memcached::DYNAMIC_CLIENT_MODE')) {
			$this->_Memcached->setOption(Memcached::OPT_CLIENT_MODE, Memcached::DYNAMIC_CLIENT_MODE);
		}

		$this->_Memcached->setOption(Memcached::OPT_COMPRESSION, (bool)$this->settings['compress']);
	}
开发者ID:NileshTailor,项目名称:dream,代码行数:31,代码来源:MemcachedEngine.php

示例2: initializeObject

 /**
  * Initializes the identifier prefix
  *
  * @return void
  * @throws Exception
  */
 public function initializeObject()
 {
     if (empty($this->servers)) {
         throw new Exception('No servers were given to Memcache', 1213115903);
     }
     $memcachedPlugin = '\\' . ucfirst($this->usedPeclModule);
     $this->memcache = new $memcachedPlugin();
     $defaultPort = $this->usedPeclModule === 'memcache' ? ini_get('memcache.default_port') : 11211;
     foreach ($this->servers as $server) {
         if (substr($server, 0, 7) === 'unix://') {
             $host = $server;
             $port = 0;
         } else {
             if (substr($server, 0, 6) === 'tcp://') {
                 $server = substr($server, 6);
             }
             if (strpos($server, ':') !== false) {
                 list($host, $port) = explode(':', $server, 2);
             } else {
                 $host = $server;
                 $port = $defaultPort;
             }
         }
         $this->memcache->addserver($host, $port);
     }
     if ($this->usedPeclModule === 'memcached') {
         $this->memcache->setOption(\Memcached::OPT_COMPRESSION, $this->getCompression());
     }
 }
开发者ID:TYPO3Incubator,项目名称:TYPO3.CMS,代码行数:35,代码来源:MemcachedBackend.php

示例3: _setOption

 /**
  * set consistent-hash
  * 每次set会自动摘除问题服务器;每次get,前两次失败后,会成功查出问题服务器
  * @param void
  * @return void
  */
 protected function _setOption($switch)
 {
     if ($this->_memcache && $switch) {
         $this->_memcache->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
         $this->_memcache->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
         $this->_memcache->setOption(Memcached::OPT_REMOVE_FAILED_SERVERS, true);
     }
 }
开发者ID:peterxiemin,项目名称:commonswoole,代码行数:14,代码来源:MemcacheWrapper.php

示例4: _setOptions

 /**
  * Settings the memcached instance
  *
  */
 protected function _setOptions()
 {
     $this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
     $this->_Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
     if (Memcached::HAVE_IGBINARY) {
         $this->_Memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY);
     }
     $this->_Memcached->setOption(Memcached::OPT_COMPRESSION, (bool) $this->settings['compress']);
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:13,代码来源:MemcachedEngine.php

示例5: setCompression

 /**
  * Setter for compression flags bit
  *
  * @param boolean $useCompression
  * @return void
  * @api
  */
 protected function setCompression($useCompression)
 {
     if ($this->memcache instanceof \Memcached) {
         $this->memcache->setOption(\Memcached::OPT_COMPRESSION, $useCompression);
     } else {
         if ($useCompression === true) {
             $this->flags ^= MEMCACHE_COMPRESSED;
         } else {
             $this->flags &= ~MEMCACHE_COMPRESSED;
         }
     }
 }
开发者ID:cerlestes,项目名称:flow-development-collection,代码行数:19,代码来源:MemcachedBackend.php

示例6: initialize

 /**
  * Initializes
  */
 private function initialize($config)
 {
     if (empty($config['servers'])) {
         return false;
     }
     if (defined('\\Memcached::OPT_REMOVE_FAILED_SERVERS')) {
         $this->_memcache->setOption(\Memcached::OPT_REMOVE_FAILED_SERVERS, true);
     }
     if (isset($config['aws_autodiscovery']) && $config['aws_autodiscovery'] && defined('\\Memcached::OPT_CLIENT_MODE') && defined('\\Memcached::DYNAMIC_CLIENT_MODE')) {
         $this->_memcache->setOption(\Memcached::OPT_CLIENT_MODE, \Memcached::DYNAMIC_CLIENT_MODE);
     }
     foreach ((array) $config['servers'] as $server) {
         if (substr($server, 0, 5) == 'unix:') {
             $this->_memcache->addServer(trim($server), 0);
         } else {
             list($ip, $port) = explode(':', $server);
             $this->_memcache->addServer(trim($ip), (int) trim($port));
         }
     }
     if (isset($config['username']) && !empty($config['username']) && method_exists($this->_memcache, 'setSaslAuthData') && ini_get('memcached.use_sasl')) {
         $this->_memcache->setSaslAuthData($config['username'], $config['password']);
     }
     return true;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:27,代码来源:Cache_Memcached.php

示例7: get_memcached

 /**
  * 获得Memcache连接
  * 
  * @return Memcache Memcache连接
  */
 public static function get_memcached()
 {
     if (Cache::$memcached === null) {
         Cache::$memcached = new Memcached('ocs');
         if (count(Cache::$memcached->getServerList()) == 0) {
             /*建立连接前,先判断*/
             /*所有option都要放在判断里面,因为有的option会导致重连,让长连接变短连接!*/
             Cache::$memcached->setOption(Memcached::OPT_COMPRESSION, false);
             Cache::$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
             /* addServer 代码必须在判断里面,否则相当于重复建立’ocs’这个连接池,可能会导致客户端php程序异常*/
             foreach (Conf::$memcached as $k => $memconf) {
                 Cache::$memcached->addServer($memconf[0], $memconf[1]);
             }
             if (Conf::$memcached_un) {
                 Cache::$memcached->setSaslAuthData(Conf::$memcached_un, Conf::$memcached_pwd);
             }
         }
         return Cache::$memcached;
     } else {
         return Cache::$memcached;
     }
 }
开发者ID:codingoneapp,项目名称:codingone,代码行数:27,代码来源:cache.php


注:本文中的Memcache::setOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。