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


PHP Memcache::addServers方法代码示例

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


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

示例1: __construct

 /**
  * Constructor
  *
  * @param array[] $servers server array
  */
 public function __construct($servers)
 {
     if (!$servers || !is_array($servers) || count($servers) < 1) {
         throw new GitPHP_MessageException('No Memcache servers defined', true, 500);
     }
     if (class_exists('Memcached')) {
         $this->memcacheObj = new Memcached();
         $this->memcacheType = GitPHP_CacheResource_Memcache::Memcached;
         $this->memcacheObj->addServers($servers);
     } else {
         if (class_exists('Memcache')) {
             $this->memcacheObj = new Memcache();
             $this->memcacheType = GitPHP_CacheResource_Memcache::Memcache;
             foreach ($servers as $server) {
                 if (is_array($server)) {
                     $host = $server[0];
                     $port = 11211;
                     if (isset($server[1])) {
                         $port = $server[1];
                     }
                     $weight = 1;
                     if (isset($server[2])) {
                         $weight = $server[2];
                     }
                     $this->memcacheObj->addServer($host, $port, true, $weight);
                 }
             }
         } else {
             throw new GitPHP_MissingMemcacheException();
         }
     }
     $this->servers = $servers;
 }
开发者ID:fboender,项目名称:gitphp,代码行数:38,代码来源:CacheResource_Memcache.class.php

示例2: __construct

 /**
  * Constructor
  *
  * @access public
  *
  * @param array $config config array
  *
  * @result void
  * @throws Exception
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     if (empty($config['type']) || !$this->check()) {
         throw new Exception('Memcache(d) not installed or not select type');
     }
     switch (strtolower($config['type'])) {
         case 'memcached':
             $this->driver = new \Memcached();
             break;
         case 'memcache':
             $this->driver = new \Memcache();
             break;
         default:
             throw new Exception('Selected type not valid in the driver');
     }
     if (!empty($config['servers'])) {
         $this->driver->addServers($config['servers']);
     } elseif ($config['server']) {
         $conf = $config['server'];
         $server = ['hostname' => !empty($conf['hostname']) ? $conf['hostname'] : '127.0.0.1', 'port' => !empty($conf['port']) ? $conf['port'] : 11211, 'weight' => !empty($conf['weight']) ? $conf['weight'] : 1];
         if (get_class($this->driver) === 'Memcached') {
             $this->driver->addServer($server['hostname'], $server['port'], $server['weight']);
         } else {
             $this->driver->addServer($server['hostname'], $server['port'], true, $server['weight']);
         }
     } else {
         throw new Exception('Server(s) not configured');
     }
 }
开发者ID:dp-ifacesoft,项目名称:micro,代码行数:40,代码来源:MemcachedCache.php

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

示例4: __construct

 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws App_Cache_Memcached_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('memcached')) {
         throw new App_Cache_Memcached_Exception('The memcache extension must be loaded for using this backend !');
     }
     if ($db = Zend_Db_Table::getDefaultAdapter()) {
         $this->_options['db'] = $db;
     } else {
         throw new App_Cache_Memcached_Exception('Can`t found Zend_Db_Table::getDefaultAdapter()!');
     }
     while (list($name, $value) = each($options)) {
         $this->setOption($name, $value);
     }
     $this->_memcached = new Memcached();
     $this->_memcached->addServers($this->_options['servers']);
 }
开发者ID:villos,项目名称:tree_admin,代码行数:23,代码来源:Memcached.php

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

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

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