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


PHP Memcache::addserver方法代码示例

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


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

示例1: __construct

 public function __construct(array $config = null)
 {
     $config = $config ?: \Kalibri::config()->get('cache');
     $this->_memcache = new \Memcache();
     foreach ($config['servers'] as $server) {
         $this->_memcache->addserver($server['host'], $server['port'], true, isset($server['weight']) ? $server['weight'] : 1);
     }
 }
开发者ID:tenebras,项目名称:kalibri,代码行数:8,代码来源:Memcache.php

示例2: init

 /**
  * Initialize memcache
  *
  * @return \Magelight\Cache\Adapter\Memcached
  */
 public function init()
 {
     $this->memcached = new \Memcache();
     foreach ((array) $this->config->xpath('servers/server') as $server) {
         $this->memcached->addserver((string) $server->host, (int) $server->port);
     }
     return $this;
 }
开发者ID:rganin,项目名称:magelight,代码行数:13,代码来源:Memcached.php

示例3: __construct

 public function __construct()
 {
     if (!class_exists('\\Memcache')) {
         throw new \PHPUnit_Framework_SkippedTestError('Test cannot be ran, you need Memcache');
     }
     $this->cache = new \Memcache();
     $this->cache->addserver("localhost");
 }
开发者ID:bcolucci,项目名称:type,代码行数:8,代码来源:MemcachedStub.php

示例4: __construct

 /**
  * Constructor
  * @param array $options cache store storage option
  */
 public function __construct($options = array())
 {
     $this->connect = new \Memcache();
     $this->prefix = $options['prefix'];
     $this->default_ttl = $options['default_ttl'];
     $this->default_flag = isset($options['default_flag']) ? $options['default_flag'] : 0;
     foreach ($options['servers'] as $server) {
         $this->connect->addserver($server[0], $server[1]);
     }
 }
开发者ID:stevleibelt,项目名称:CacheStore,代码行数:14,代码来源:Memcache.php

示例5: init

 /**
  * {@inheritDoc}
  */
 public function init(array $connections)
 {
     if (!class_exists("\\Memcache")) {
         throw new \Exception("'Memcache' class does not exist. Please install it to be able to use the Memcache connections");
     }
     $this->memcache = new \Memcache();
     foreach ($connections as $connection) {
         $this->memcache->addserver($connection["host"], $connection["port"]);
     }
 }
开发者ID:urodoz,项目名称:cachemanager,代码行数:13,代码来源:MemcacheImplementation.php

示例6: addServer

 protected function addServer(array $server)
 {
     if (!array_key_exists('host', $server)) {
         throw new \InvalidArgumentException('host key must be set');
     }
     $server['port'] = isset($server['port']) ? (int) $server['port'] : 11211;
     $server['timeout'] = isset($server['timeout']) ? (int) $server['timeout'] : 1;
     $server['persistent'] = isset($server['persistent']) ? (bool) $server['persistent'] : false;
     $server['weight'] = isset($server['weight']) ? (int) $server['weight'] : 1;
     $server['retry_interval'] = isset($server['retry_interval']) ? (int) $server['retry_interval'] : 15;
     $this->memcache->addserver($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval']);
 }
开发者ID:rouffj,项目名称:symfony,代码行数:12,代码来源:MemcacheSessionHandler.php

示例7: __construct

 /**
  * Construct the adapter, giving an array of servers.
  * @example
  *     array(
  *         array(
  *             'host' => 'cache1.example.com',
  *             'port' => 11211,
  *             'weight' => 1,
  *             'timeout' => 60
  *         ),
  *         array(
  *             'host' => 'cache2.example.com',
  *             'port' => 11211,
  *             'weight' => 2,
  *             'timeout' => 60
  *         )
  *     )
  * @param array $servers
  */
 public function __construct(array $servers)
 {
     try {
         $this->memcache = new \Memcache();
         foreach ($servers as $server) {
             $this->memcache->addserver($server['host'], $server['port'], null, $server['weight'], $server['timeout']);
         }
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $this->memcache = null;
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:phavour,项目名称:phavour,代码行数:32,代码来源:AdapterMemcache.php

示例8: __construct

 /**
  * @param $cache
  * @param $period
  * @param string $cachePrefix
  * @throws \Exception
  */
 public function __construct($cache, $period, $cachePrefix = 'informers')
 {
     $this->period = $period;
     $this->cachePrefix = $cachePrefix;
     if ($cache instanceof \Memcache) {
         $this->cache = $cache;
     } elseif (is_array($cache)) {
         $this->cache = new \Memcache();
         $this->cache->addserver($cache['host'], $cache['port']);
     } else {
         throw new ClientException('Incorrect cache configuration');
     }
 }
开发者ID:deliverynetwork,项目名称:informers-client-php,代码行数:19,代码来源:MemoryCache.php

示例9: __construct

 /**
  * Construct the Memcache based cache provider
  * @param array $objOptionsArray array of server options. Each item in the array contains an associative
  * arrays with options for the server to add to memcache
  */
 public function __construct($objOptionsArray)
 {
     $this->objMemcache = new Memcache();
     foreach ($objOptionsArray as $objServerOptions) {
         $host = $objServerOptions["host"];
         $port = array_key_exists("port", $objServerOptions) ? $objServerOptions["port"] : 11211;
         $persistent = array_key_exists("persistent", $objServerOptions) ? $objServerOptions["persistent"] : true;
         $weight = array_key_exists("weight", $objServerOptions) ? $objServerOptions["weight"] : 10;
         $timeout = array_key_exists("timeout", $objServerOptions) ? $objServerOptions["timeout"] : 1;
         $retry_interval = array_key_exists("retry_interval", $objServerOptions) ? $objServerOptions["retry_interval"] : 15;
         $status = array_key_exists("status", $objServerOptions) ? $objServerOptions["status"] : true;
         $failure_callback = array_key_exists("failure_callback", $objServerOptions) ? $objServerOptions["failure_callback"] : null;
         $this->objMemcache->addserver($host, $port, $persistent, $weight, $timeout, $retry_interval, $status, $failure_callback);
     }
 }
开发者ID:hiptc,项目名称:dle2wordpress,代码行数:20,代码来源:QCacheProviderMemcache.class.php

示例10: __construct

 /**
  * Конструктор кеша
  */
 public function __construct()
 {
     //Проверяем ключи в конфиге
     if (!isset(Boot::getInstance()->config->memcache->host) || !isset(Boot::getInstance()->config->memcache->port)) {
         throw new Boot_Exception('Не указаны настройки Memcache', 500);
     }
     //Добавляем префикс
     if (isset(Boot::getInstance()->config->memcache->prefix)) {
         $this->prefix = Boot::getInstance()->config->memcache->prefix . "::";
     }
     //Инициализируем класс кеша
     $this->m = new Memcache();
     //Добавляем сервер
     $this->m->addserver(Boot::getInstance()->config->memcache->host, Boot::getInstance()->config->memcache->port);
 }
开发者ID:pnixx,项目名称:boot,代码行数:18,代码来源:cache.php

示例11: register

 public function register(Application $app)
 {
     $app->setParameter('cache', ['namespace' => null, 'type' => 'array']);
     $app->singleton('cache', function () use($app) {
         $cache = null;
         $type = $app->getParameter('cache.type', 'array');
         if ($type == 'array') {
             $cache = new ArrayCache();
         } elseif ($type == 'apc') {
             $cache = new ApcCache();
         } elseif ($type == 'xcache') {
             $cache = new XcacheCache();
         } elseif ($type == 'memcache') {
             $cache = new MemcacheCache();
             $memcache = new \Memcache();
             $memcache->addserver($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211));
             $cache->setMemcache($memcache);
         } elseif ($type == 'memcached') {
             $cache = new MemcachedCache();
             $memcached = new \Memcached();
             $memcached->addServer($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211));
             $cache->setMemcached($memcached);
         }
         $cache->setNamespace($app->getParameter('cache.namespace'));
         return $cache;
     });
 }
开发者ID:itlessons,项目名称:php-application,代码行数:27,代码来源:DoctrineCacheProvider.php

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

示例13: initializeObject

 /**
  * Initializes the identifier prefix
  *
  * @return void
  * @throws \TYPO3\CMS\Core\Cache\Exception
  */
 public function initializeObject()
 {
     if (empty($this->servers)) {
         throw new \TYPO3\CMS\Core\Cache\Exception('No servers were given to Memcache', 1213115903);
     }
     $this->memcache = new \Memcache();
     $defaultPort = ini_get('memcache.default_port');
     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);
     }
 }
开发者ID:rickymathew,项目名称:TYPO3.CMS,代码行数:31,代码来源:MemcachedBackend.php

示例14: testSetInstanceSuccess

 public function testSetInstanceSuccess()
 {
     $driver = $this->getDriver();
     $client = new \Memcache();
     $client->addserver('localhost');
     $driver->setInstance($client);
 }
开发者ID:noikiy,项目名称:owl,代码行数:7,代码来源:MemcacheTest.php

示例15: __construct

 /**
  * Construct the adapter, giving an array of servers.
  * @example
  *     array(
  *         'prefix' => '',
  *         'servers' => array(
  *             array (
  *                 'host' => 'cache1.example.com',
  *                 'port' => 11211,
  *                 'weight' => 1,
  *                 'timeout' => 60
  *             ),
  *             array(
  *                 'host' => 'cache2.example.com',
  *                 'port' => 11211,
  *                 'weight' => 2,
  *                 'timeout' => 60
  *             )
  *         )
  *     )
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     try {
         if (array_key_exists('prefix', $config)) {
             $this->prefix = $config['prefix'];
         }
         $this->memcache = new \Memcache();
         foreach ($config['servers'] as $server) {
             $this->memcache->addserver($server['host'], $server['port'], null, $server['weight'], $server['timeout']);
         }
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $this->memcache = null;
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:rogerthomas84,项目名称:ohcache,代码行数:38,代码来源:AdapterMemcache.php


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