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


PHP Memcache::getServerList方法代码示例

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


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

示例1: init

 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $settings array of setting for the engine
  * @return bool True if the engine has been successfully initialized, false if not
  */
 public function init($settings = [])
 {
     if (!class_exists('Memcached')) {
         return false;
     }
     if (!isset($settings['prefix'])) {
         $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     $settings += ['engine' => 'Memcached', 'servers' => ['127.0.0.1'], 'compress' => false, 'persistent' => true];
     parent::init($settings);
     $this->_keys .= $this->settings['prefix'];
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = [$this->settings['servers']];
     }
     if (!isset($this->_Memcached)) {
         $return = false;
         $this->_Memcached = new Memcached($this->settings['persistent'] ? 'mc' : null);
         $this->_setOptions();
         if (!count($this->_Memcached->getServerList())) {
             $servers = [];
             foreach ($this->settings['servers'] as $server) {
                 $servers[] = $this->_parseServerString($server);
             }
             if ($this->_Memcached->addServers($servers)) {
                 $return = true;
             }
         }
         if (!$this->_Memcached->get($this->_keys)) {
             $this->_Memcached->set($this->_keys, '');
         }
         return $return;
     }
     return true;
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:43,代码来源:MemcachedEngine.php

示例2: init

 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $settings array of setting for the engine
  * @return bool True if the engine has been successfully initialized, false if not
  * @throws CacheException when you try use authentication without Memcached compiled with SASL support
  */
 public function init($settings = array())
 {
     if (!class_exists('Memcached')) {
         return false;
     }
     if (!isset($settings['prefix'])) {
         $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     if (defined('Memcached::HAVE_MSGPACK') && Memcached::HAVE_MSGPACK) {
         $this->_serializers['msgpack'] = Memcached::SERIALIZER_MSGPACK;
     }
     $settings += array('engine' => 'Memcached', 'servers' => array('127.0.0.1'), 'compress' => false, 'persistent' => false, 'login' => null, 'password' => null, 'serialize' => 'php', 'options' => array());
     parent::init($settings);
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (isset($this->_Memcached)) {
         return true;
     }
     if (!$this->settings['persistent']) {
         $this->_Memcached = new Memcached();
     } else {
         $this->_Memcached = new Memcached((string) $this->settings['persistent']);
     }
     $this->_setOptions();
     if (count($this->_Memcached->getServerList())) {
         return true;
     }
     $servers = array();
     foreach ($this->settings['servers'] as $server) {
         $servers[] = $this->_parseServerString($server);
     }
     if (!$this->_Memcached->addServers($servers)) {
         return false;
     }
     if ($this->settings['login'] !== null && $this->settings['password'] !== null) {
         if (!method_exists($this->_Memcached, 'setSaslAuthData')) {
             throw new CacheException(__d('cake_dev', 'Memcached extension is not build with SASL support'));
         }
         $this->_Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
         $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
     }
     if (is_array($this->settings['options'])) {
         foreach ($this->settings['options'] as $opt => $value) {
             $this->_Memcached->setOption($opt, $value);
         }
     }
     return true;
 }
开发者ID:medinaccesar,项目名称:blogcake,代码行数:59,代码来源:MemcachedEngine.php

示例3: _addServer

 /**
  * @param array $serverInfo
  */
 protected function _addServer($serverInfo)
 {
     if (!isset($serverInfo['host']) || !isset($serverInfo['port'])) {
         throw new RuntimeException('illigal server info, host and port is required');
     }
     $serverInfo = array_merge(self::$_baseServerInfo, $serverInfo);
     $servers = $this->_memcache->getServerList();
     if (is_array($servers)) {
         foreach ($servers as $server) {
             if ($server['host'] == $serverInfo['host'] && $server['port'] == $serverInfo['port']) {
                 return true;
             }
         }
     }
     $this->_memcache->addServer($serverInfo['host'], $serverInfo['port']);
 }
开发者ID:peterxiemin,项目名称:commonswoole,代码行数:19,代码来源:MemcacheWrapper.php

示例4: get_stats_size

 /**
  * Returns size used by cache
  */
 public function get_stats_size($timeout_time)
 {
     $size = array('bytes' => 0, 'items' => 0, 'timeout_occurred' => false);
     $key_prefix = $this->get_item_key('');
     $error_occurred = false;
     $server_list = $this->_memcache->getServerList();
     $n = 0;
     foreach ($server_list as $server) {
         $loader = new Cache_Memcached_Stats($server['host'], $server['port']);
         $slabs = $loader->slabs();
         if (!is_array($slabs)) {
             $error_occurred = true;
             continue;
         }
         foreach ($slabs as $slab_id) {
             $cdump = $loader->cachedump($slab_id);
             if (!is_array($cdump)) {
                 continue;
             }
             foreach ($cdump as $line) {
                 $key_data = explode(' ', $line);
                 if (!is_array($key_data) || count($key_data) < 3) {
                     continue;
                 }
                 $n++;
                 if ($n % 10 == 0) {
                     $size['timeout_occurred'] = time() > $timeout_time;
                     if ($size['timeout_occurred']) {
                         return $size;
                     }
                 }
                 $key = $key_data[1];
                 $bytes = substr($key_data[2], 1);
                 if (substr($key, 0, strlen($key_prefix)) == $key_prefix) {
                     $size['bytes'] += $bytes;
                     $size['items']++;
                 }
             }
         }
     }
     if ($error_occurred && $size['items'] <= 0) {
         $size['bytes'] = null;
         $size['items'] = null;
     }
     return $size;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:49,代码来源:Cache_Memcached.php

示例5: init

 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  *
  * @param array $config array of setting for the engine
  * @return bool True if the engine has been successfully initialized, false if not
  * @throws \Cake\Error\Exception when you try use authentication without Memcached compiled with SASL support
  */
 public function init(array $config = [])
 {
     if (!class_exists('Memcached')) {
         return false;
     }
     if (!isset($config['prefix'])) {
         $config['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     if (defined('Memcached::HAVE_MSGPACK') && Memcached::HAVE_MSGPACK) {
         $this->_serializers['msgpack'] = Memcached::SERIALIZER_MSGPACK;
     }
     parent::init($config);
     if (isset($config['servers'])) {
         $this->config('servers', $config['servers'], false);
     }
     if (!is_array($this->_config['servers'])) {
         $this->_config['servers'] = [$this->_config['servers']];
     }
     if (isset($this->_Memcached)) {
         return true;
     }
     $this->_Memcached = new \Memcached($this->_config['persistent'] ? (string) $this->_config['persistent'] : null);
     $this->_setOptions();
     if (count($this->_Memcached->getServerList())) {
         return true;
     }
     $servers = [];
     foreach ($this->_config['servers'] as $server) {
         $servers[] = $this->_parseServerString($server);
     }
     if (!$this->_Memcached->addServers($servers)) {
         return false;
     }
     if ($this->_config['login'] !== null && $this->_config['password'] !== null) {
         if (!method_exists($this->_Memcached, 'setSaslAuthData')) {
             throw new Error\Exception('Memcached extension is not build with SASL support');
         }
         $this->_Memcached->setSaslAuthData($this->_config['login'], $this->_config['password']);
     }
     return true;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:50,代码来源:MemcachedEngine.php

示例6: 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

示例7: init

 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $settings array of setting for the engine
  * @return boolean True if the engine has been successfully initialized, false if not
  * @throws CacheException when you try use authentication without Memcached compiled with SASL support
  */
 public function init($settings = array())
 {
     if (!class_exists('Memcached')) {
         return false;
     }
     if (!isset($settings['prefix'])) {
         $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     $settings += array('engine' => 'Memcached', 'servers' => array('127.0.0.1'), 'compress' => false, 'persistent' => false, 'login' => null, 'password' => null, 'serialize' => 'php');
     parent::init($settings);
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (isset($this->_Memcached)) {
         return true;
     }
     $this->_Memcached = new Memcached($this->settings['persistent'] ? (string) $this->settings['persistent'] : null);
     $this->_setOptions();
     if (count($this->_Memcached->getServerList())) {
         return true;
     }
     $servers = array();
     foreach ($this->settings['servers'] as $server) {
         $servers[] = $this->_parseServerString($server);
     }
     if (!$this->_Memcached->addServers($servers)) {
         return false;
     }
     if ($this->settings['login'] !== null && $this->settings['password'] !== null) {
         if (!method_exists($this->_Memcached, 'setSaslAuthData')) {
             throw new CacheException(__d('cake_dev', 'Memcached extension is not build with SASL support'));
         }
         $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
     }
     return true;
 }
开发者ID:dllen,项目名称:CakePHP-Memcached-Engine,代码行数:46,代码来源:MemcachedEngine.php


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