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


PHP Memcached::addServer方法代码示例

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


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

示例1: __construct

 /**
  * Initialise memcached storage cache.
  *
  * @param array $options optional config array, valid keys are: host, port
  */
 public function __construct(array $options = array())
 {
     $this->options = $options + $this->options;
     $this->memcached = new \Memcached();
     $this->memcached->addServer($this->options['host'], $this->options['port'], 0);
     $this->flags = $this->options['compressed'] ? MEMCACHED_COMPRESSED : 0;
 }
开发者ID:addrever,项目名称:ecat,代码行数:12,代码来源:MemcachedStorage.php

示例2: __construct

 public function __construct($persistent = true)
 {
     /*
      * Caching can be disabled in the config file if you aren't able to run
      * a memcached instance.  In that case this class will still get used,
      * but we will pretend that we have a perpetually empty cache.
      */
     if (defined("USE_MEMCACHED") && USE_MEMCACHED != false) {
         $servers = null;
         if ($persistent === true) {
             /*
              * Since prefix should be unique across RTK installations, we can
              * use the server hostname + port + prefix as a persistent ID.
              * Hostname + port are included because otherwise changing the
              * memcached server would NOT change the persistent connection,
              * and you'd end up using the old server.
              */
             $persistentID = MEMCACHED_HOST . ":" . MEMCACHED_PORT . "_" . MEMCACHED_PREFIX;
             $this->cache = new Memcached($persistentID);
             $serverList = $this->cache->getServerList();
             foreach ($serverList as $entry) {
                 $servers[] = $entry['host'] . ":" . $entry['port'];
             }
         } else {
             //Not running Memcached in persistent mode.
             $this->cache = new Memcached();
         }
         if ($persistent !== true || !is_array($servers) || !in_array(MEMCACHED_HOST . ":" . MEMCACHED_PORT, $servers)) {
             $this->cache->addServer(MEMCACHED_HOST, MEMCACHED_PORT);
         }
     }
 }
开发者ID:Covert-Inferno,项目名称:reaction-toolkit,代码行数:32,代码来源:CacheManager.php

示例3: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     static::$Memcached = new \Memcached();
     // MEMCACHED_TEST_SERVER defined in phpunit.xml
     $server = explode(':', MEMCACHED_TEST_SERVER);
     static::$Memcached->addServer($server[0], $server[1]);
 }
开发者ID:cheprasov,项目名称:php-memcached-tags,代码行数:7,代码来源:MemcachedTagsTest.php

示例4: __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

示例5: __construct

 public function __construct(array $aConfig = [])
 {
     // Parent construct
     parent::__construct($aConfig);
     // Extend config
     $aConfig = ExtendedArray::extendWithDefaultValues($aConfig, ['connection_timeout' => 10, 'server_failure_limit' => 5, 'remove_failed_servers' => true, 'retry_timeout' => 1]);
     // Check Memcached is loaded
     if (!extension_loaded('memcached')) {
         throw new RuntimeException('Memcached extension is not loaded');
     }
     // Create client
     $this->oClient = new Memcached();
     $this->oClient->setOption(Memcached::OPT_CONNECT_TIMEOUT, $aConfig['connection_timeout']);
     $this->oClient->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
     $this->oClient->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, $aConfig['server_failure_limit']);
     $this->oClient->setOption(Memcached::OPT_REMOVE_FAILED_SERVERS, $aConfig['remove_failed_servers']);
     $this->oClient->setOption(Memcached::OPT_RETRY_TIMEOUT, $aConfig['retry_timeout']);
     // Add servers
     if (array_key_exists('servers', $aConfig)) {
         $aServers = array_filter(explode(',', $aConfig['servers']));
         foreach ($aServers as $sAddress) {
             // Parse address
             list($sHost, $sPort) = array_pad(explode(':', $sAddress), 2, '');
             // Add server
             $this->oClient->addServer($sHost, intval($sPort));
         }
     }
 }
开发者ID:asticode,项目名称:php-cache-manager,代码行数:28,代码来源:MemcachedHandler.php

示例6: __construct

 public function __construct()
 {
     $this->mem = new Memcached(static::$servers_id);
     if (count($this->mem->getServerList()) == 0) {
         $this->mem->addServer("", 11211);
     }
 }
开发者ID:Natio,项目名称:WebSherpa,代码行数:7,代码来源:PCCacheMemcached.php

示例7: setupMemcache

 private function setupMemcache()
 {
     if (is_null($this->memcache) && class_exists('Memcached', false)) {
         $this->memcache = new \Memcached();
         $this->memcache->addServer($this->host, $this->port);
     }
 }
开发者ID:ineersa,项目名称:currency-converter,代码行数:7,代码来源:MemcacheCache.php

示例8: addServer

 public function addServer($host = 'localhost', $port = 11211)
 {
     if ($this->memcached->addServer($host, $port, 1) === FALSE) {
         $error = error_get_last();
         throw new Nette\InvalidStateException("Memcached::addServer(): {$error['message']}.");
     }
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:7,代码来源:NewMemcachedStorage.php

示例9: __construct

 /**
  * Constructor
  *
  * @param string $uniqId to be used to separate objects in addition to their key identifiers, for instance in a
  * multi-user scenario.
  *
  * @return \iveeCrest\MemcachedWrapper
  */
 public function __construct($uniqId)
 {
     $this->memcached = new \Memcached();
     $this->memcached->addServer(Config::getCacheHost(), Config::getCachePort());
     $this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, Config::getCachePrefix());
     $this->uniqId = $uniqId;
 }
开发者ID:plugh3,项目名称:eve-trade1-perl,代码行数:15,代码来源:MemcachedWrapper.php

示例10: __construct

 /**
  * Creamos y configuramos el driver para la cache.
  * @param string $hostname Nombre del host para conectar al servidor memcached.
  * @param int $port Puerto para conectar al servidor de memcached.
  * @param int $weight Importancia del servidor frente al resto.
  */
 public function __construct($hostname = '127.0.0.1', $port = 11211, $weight = 1)
 {
     // Instanciamos memcached.
     $this->_memcached = new Memcached();
     // Configuramos el servidor.
     $this->_memcached->addServer($hostname, $port, $weight);
 }
开发者ID:4bs4,项目名称:marifa,代码行数:13,代码来源:memcached.php

示例11: init

 protected function init()
 {
     $this->config['host'] = $this->config['host'] ?: 'localhost';
     $this->config['port'] = $this->config['port'] ?: 11211;
     $this->store = new Memcached();
     $this->store->addServer($this->config['host'], $this->config['port'], 100);
 }
开发者ID:simon-downes,项目名称:spf,代码行数:7,代码来源:Memcache.php

示例12: connectServer

 /**
  * @return bool
  */
 public function connectServer()
 {
     if ($this->checkdriver() == false) {
         return false;
     }
     $s = $this->config['memcache'];
     if (count($s) < 1) {
         $s = array(array('127.0.0.1', 11211, 100));
     }
     foreach ($s as $server) {
         $name = isset($server[0]) ? $server[0] : '127.0.0.1';
         $port = isset($server[1]) ? $server[1] : 11211;
         $sharing = isset($server[2]) ? $server[2] : 0;
         $checked = $name . '_' . $port;
         if (!isset($this->checked[$checked])) {
             try {
                 if ($sharing > 0) {
                     if (!$this->instant->addServer($name, $port, $sharing)) {
                         $this->fallback = true;
                     }
                 } else {
                     if (!$this->instant->addServer($name, $port)) {
                         $this->fallback = true;
                     }
                 }
                 $this->checked[$checked] = 1;
             } catch (\Exception $e) {
                 $this->fallback = true;
             }
         }
     }
 }
开发者ID:dudusouza,项目名称:wowadmin,代码行数:35,代码来源:memcached.php

示例13: connect

 /**
  * Connect and initialize this handler.
  *
  * @return boolean True if successful, false on failure
  */
 function connect()
 {
     global $mybb, $error_handler;
     $this->memcached = new Memcached();
     if ($mybb->config['memcache']['host']) {
         $mybb->config['memcache'][0] = $mybb->config['memcache'];
         unset($mybb->config['memcache']['host']);
         unset($mybb->config['memcache']['port']);
     }
     foreach ($mybb->config['memcache'] as $memcached) {
         if (!$memcached['host']) {
             $message = "Please configure the memcache settings in inc/config.php before attempting to use this cache handler";
             $error_handler->trigger($message, MYBB_CACHEHANDLER_LOAD_ERROR);
             die;
         }
         if (!isset($memcached['port'])) {
             $memcached['port'] = "11211";
         }
         $this->memcached->addServer($memcached['host'], $memcached['port']);
         if (!$this->memcached) {
             $message = "Unable to connect to the memcached server on {$memcached['memcache_host']}:{$memcached['memcache_port']}. Are you sure it is running?";
             $error_handler->trigger($message, MYBB_CACHEHANDLER_LOAD_ERROR);
             die;
         }
     }
     // Set a unique identifier for all queries in case other forums are using the same memcache server
     $this->unique_id = md5(MYBB_ROOT);
     return true;
 }
开发者ID:mainhan1804,项目名称:xomvanphong,代码行数:34,代码来源:memcached.php

示例14: connect

 /**
  * Only connect at the last possible moment. This enables you to get the cache provider, but not connect
  * until you have business with the cache.
  */
 private function connect()
 {
     if ($this->isConnected) {
         return;
     }
     $this->memcache->addServer($this->configuration->getHost(), $this->configuration->getPort());
 }
开发者ID:digitalcreations,项目名称:cache-memcached,代码行数:11,代码来源:Cache.php

示例15: __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


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