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


PHP Memcache::addServer方法代码示例

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


在下文中一共展示了Memcache::addServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 boolean True if the engine has been successfully initialized, false if not
  */
 public function init($settings = array())
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     if (!isset($settings['prefix'])) {
         $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     $settings += array('engine' => 'Memcache', 'servers' => array('127.0.0.1'), 'compress' => false, 'persistent' => true);
     parent::init($settings);
     if ($this->settings['compress']) {
         $this->settings['compress'] = MEMCACHE_COMPRESSED;
     }
     if (is_string($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (!isset($this->_Memcache)) {
         $return = false;
         $this->_Memcache = new Memcache();
         foreach ($this->settings['servers'] as $server) {
             list($host, $port) = $this->_parseServerString($server);
             if ($this->_Memcache->addServer($host, $port, $this->settings['persistent'])) {
                 $return = true;
             }
         }
         return $return;
     }
     return true;
 }
开发者ID:4Queen,项目名称:php-buildpack,代码行数:38,代码来源:MemcacheEngine.php

示例2: __construct

 /**
  * Creates a new MemcacheAdapter object.
  */
 private function __construct()
 {
     if (!class_exists('Memcache')) {
         throw new SystemException('memcache support is not enabled.');
     }
     // init memcache
     $this->memcache = new Memcache();
     // add servers
     $servers = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHE_HOST));
     foreach ($servers as $server) {
         $server = StringUtil::trim($server);
         if (!empty($server)) {
             $host = $server;
             $port = 11211;
             // default memcache port
             // get port
             if (strpos($host, ':')) {
                 $parsedHost = explode(':', $host);
                 $host = $parsedHost[0];
                 $port = $parsedHost[1];
             }
             $this->memcache->addServer($host, $port, CACHE_SOURCE_MEMCACHE_USE_PCONNECT);
         }
     }
     // test connection
     $this->memcache->get('testing');
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:30,代码来源:MemcacheAdapter.class.php

示例3: __construct

 /**
  * Construct 
  * 
  * @param array $options Cache options
  *
  * @return void
  */
 public function __construct(array $options)
 {
     $this->cache = new Memcache();
     foreach ($options['servers'] as $server) {
         $this->cache->addServer($server['host'], $server['port'], $server['timeout']);
     }
 }
开发者ID:ntulip,项目名称:DiggLite,代码行数:14,代码来源:Memcache.php

示例4: Memcache

 /**
  * Check for existence of the memcache extension and
  * constructs the memcache Cache object
  *
  * @param   array configuration
  * @throws  Cache_Exception
  */
 function CI_Cache_Memcache($config)
 {
     // Check for the memcache extention
     if (!extension_loaded('memcache')) {
         show_error('Memcache PHP extention not loaded.');
     }
     $this->conf = $config;
     // Setup Memcache
     $this->memcache = new Memcache();
     // Load servers from configuration
     $servers = $config['servers'];
     if (!$servers) {
         // Throw an exception if no server found
         show_error('No Memcache servers defined in configuration');
     }
     // Setup default server configuration
     $config = array('host' => 'localhost', 'port' => 11211, 'persistent' => FALSE, 'weight' => 1, 'timeout' => 1, 'retry_interval' => 15, 'status' => TRUE, 'failure_callback' => array($this, '_failed_request'));
     // Add the memcache servers to the pool
     foreach ($servers as $server) {
         // Merge the defined config with defaults
         $server += $config;
         if (!$this->memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['failure_callback'])) {
             show_error('Memcache could not connect  to host ' . $server['host'] . ' using port ' . $server['port']);
         }
     }
     // Setup the flags
     $this->flags = $this->conf['compression'] !== FALSE ? MEMCACHE_COMPRESSED : FALSE;
 }
开发者ID:googlecode-mirror,项目名称:f-engine,代码行数:35,代码来源:memcache.php

示例5: __construct

 /**
  * Crea una instancia del Adaptador y pasa configuraciones.
  *
  * @param array $config Configuraciones
  */
 public function __construct(array $config)
 {
     $this->gestor = new \Memcache();
     foreach ($config['servidores'] as $servidor) {
         $this->gestor->addServer($servidor[0], $servidor[1], true, $servidor[2]);
     }
 }
开发者ID:armazon,项目名称:armazon,代码行数:12,代码来源:Memcache.php

示例6: addServer

 public function addServer($host = 'localhost', $port = 11211, $timeout = 1)
 {
     if ($this->memcache->addServer($host, $port, TRUE, 1, $timeout) === FALSE) {
         $error = error_get_last();
         throw new Nette\InvalidStateException("Memcache::addServer(): {$error['message']}.");
     }
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:7,代码来源:MemcachedStorage.php

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

示例8: init

 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $setting array of setting for the engine
  * @return boolean True if the engine has been successfully initialized, false if not
  * @access public
  */
 function init($settings = array())
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     parent::init(array_merge(array('engine' => 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), 'compress' => false), $settings));
     if ($this->settings['compress']) {
         $this->settings['compress'] = MEMCACHE_COMPRESSED;
     }
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (!isset($this->__Memcache)) {
         $return = false;
         $this->__Memcache =& new Memcache();
         foreach ($this->settings['servers'] as $server) {
             $parts = explode(':', $server);
             $host = $parts[0];
             $port = 11211;
             if (isset($parts[1])) {
                 $port = $parts[1];
             }
             if ($this->__Memcache->addServer($host, $port)) {
                 $return = true;
             }
         }
         return $return;
     }
     return true;
 }
开发者ID:maverick2041,项目名称:wpkgexpress,代码行数:40,代码来源:memcache.php

示例9: getConnection

 /**
  * Return memcache connection object
  *
  * @return  object   memcache connection object
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 protected function getConnection()
 {
     if ((extension_loaded('memcache') && class_exists('Memcache')) != true) {
         return false;
     }
     $config = JFactory::getConfig();
     $this->_persistent = $config->get('memcache_persist', true);
     $this->_compress = $config->get('memcache_compress', false) == false ? 0 : MEMCACHE_COMPRESSED;
     /*
      * This will be an array of loveliness
      * @todo: multiple servers
      * $servers	= (isset($params['servers'])) ? $params['servers'] : array();
      */
     $server = array();
     $server['host'] = $config->get('memcache_server_host', 'localhost');
     $server['port'] = $config->get('memcache_server_port', 11211);
     // Create the memcache connection
     self::$_db = new Memcache();
     self::$_db->addServer($server['host'], $server['port'], $this->_persistent);
     $memcachetest = @self::$_db->connect($server['host'], $server['port']);
     if ($memcachetest == false) {
         throw new RuntimeException('Could not connect to memcache server', 404);
     }
     // Memcahed has no list keys, we do our own accounting, initialise key index
     if (self::$_db->get($this->_hash . '-index') === false) {
         $empty = array();
         self::$_db->set($this->_hash . '-index', $empty, $this->_compress, 0);
     }
     return;
 }
开发者ID:ZerGabriel,项目名称:joomla-platform,代码行数:38,代码来源:memcache.php

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

示例11: open

 /**
  * opening of the session - mandatory arguments won't be needed
  *
  * @param string $savePath
  * @param string $sessionName
  * @return bool
  */
 public function open($savePath, $sessionName)
 {
     if (!isset($this->_lifeTime)) {
         $this->_lifeTime = intval(ini_get("session.gc_maxlifetime"));
     }
     if (!isset($this->_refreshTime)) {
         $this->_refreshTime = ceil($this->_lifeTime / 3);
     }
     $this->_initSessionData = null;
     $this->_memcache = new Memcache();
     if (Kwf_Config::getValue('aws.simpleCacheCluster')) {
         $servers = Kwf_Util_Aws_ElastiCache_CacheClusterEndpoints::getCached(Kwf_Config::getValue('aws.simpleCacheCluster'));
     } else {
         if (Kwf_Cache_Simple::$memcacheHost) {
             $servers = array(array('host' => Kwf_Cache_Simple::$memcacheHost, 'port' => Kwf_Cache_Simple::$memcachePort));
         } else {
             throw new Kwf_Exception("no memcache configured");
         }
     }
     foreach ($servers as $s) {
         if (version_compare(phpversion('memcache'), '2.1.0') == -1 || phpversion('memcache') == '2.2.4') {
             // < 2.1.0
             $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
         } else {
             if (version_compare(phpversion('memcache'), '3.0.0') == -1) {
                 // < 3.0.0
                 $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1, true, null, 10000);
             } else {
                 $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
             }
         }
     }
     return true;
 }
开发者ID:xiaoguizhidao,项目名称:koala-framework,代码行数:41,代码来源:SessionHandler.php

示例12: connect

 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     foreach ($this->options['servers'] as $server) {
         $server = $server + $this->options['defaultServer'];
         $this->service->addServer($server['host'], $server['port'], $server['persistent'], $server['weight']);
     }
 }
开发者ID:jwdeitch,项目名称:components,代码行数:10,代码来源:MemcacheDriver.php

示例13: connect

 /**
  * Connect and initialize this handler.
  *
  * @return boolean True if successful, false on failure
  */
 function connect()
 {
     global $mybb, $error_handler;
     $this->memcache = new Memcache();
     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 $memcache) {
         if (!$memcache['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($memcache['port'])) {
             $memcache['port'] = "11211";
         }
         $this->memcache->addServer($memcache['host'], $memcache['port']);
         if (!$this->memcache) {
             $message = "Unable to connect to the memcache server on {$memcache['memcache_host']}:{$memcache['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,代码来源:memcache.php

示例14: __construct

 /**
  * constructor
  *
  * @param array $options        associative array of cache driver options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcache')) {
         throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.');
     }
     parent::__construct($options);
     if (isset($options['servers'])) {
         $value = $options['servers'];
         if (isset($value['host'])) {
             // in this case, $value seems to be a simple associative array (one server only)
             $value = array(0 => $value);
             // let's transform it into a classical array of associative arrays
         }
         $this->setOption('servers', $value);
     }
     $this->_memcache = new Memcache();
     foreach ($this->_options['servers'] as $server) {
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = true;
         }
         if (!array_key_exists('port', $server)) {
             $server['port'] = 11211;
         }
         $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']);
     }
 }
开发者ID:atikahmed,项目名称:joomla-probid,代码行数:31,代码来源:Memcache.php

示例15: connect

 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     foreach ($this->servers as $server) {
         $server = $server + $this->defaultServer;
         $this->driver->addServer($server['host'], $server['port'], $server['persistent'], $server['weight']);
     }
 }
开发者ID:tuneyourserver,项目名称:components,代码行数:10,代码来源:MemcacheDriver.php


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