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


PHP Memcached::addserver方法代码示例

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


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

示例1: __construct

 /**
  * Construct the adapter, giving an array of servers.
  * @example
  *     array(
  *         'prefix' => '',
  *         'persistent_id' => '',
  *         'servers' => array(
  *             array (
  *                 'host' => 'cache1.example.com',
  *                 'port' => 11211,
  *                 'weight' => 1
  *             ),
  *             array(
  *                 'host' => 'cache2.example.com',
  *                 'port' => 11211,
  *                 'weight' => 2
  *             )
  *         )
  *     )
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     try {
         if (array_key_exists('prefix', $config)) {
             $this->prefix = $config['prefix'];
         }
         if (array_key_exists('persistent_id', $config) && !empty($config['persistent_id'])) {
             // @codeCoverageIgnoreStart
             $this->memcached = new \Memcached($config['persistent_id']);
         } else {
             // @codeCoverageIgnoreEnd
             $this->memcached = new \Memcached();
         }
         foreach ($config['servers'] as $server) {
             $this->memcached->addserver($server['host'], $server['port'], $server['weight']);
         }
         if (array_key_exists('options', $config)) {
             foreach ($config['options'] as $optionKey => $optionValue) {
                 $this->memcached->setOption($optionKey, $optionValue);
             }
         }
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $this->memcached = null;
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:rogerthomas84,项目名称:ohcache,代码行数:48,代码来源:AdapterMemcached.php

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

示例3: initialize

 /**
  * Sets up and returns the CacheProvider
  * @param $config
  * @return \Doctrine\Common\Cache\CacheProvider
  */
 protected function initialize($config)
 {
     $memcached = new \Memcached();
     $memcached->addserver($config['host'], $config['port']);
     $cache = new MemcachedCache();
     $cache->setMemcached($memcached);
     return $cache;
 }
开发者ID:atrauzzi,项目名称:laravel-doctrine,代码行数:13,代码来源:MemcachedProvider.php

示例4: __construct

    /**
     * Initializes usage of memcache or memcached
     */
    private function __construct()
    {
        $ini = eZINI::instance('merck.ini');
        if ( $ini->hasSection('MemcacheSettings') )
        {
            $this->_host = $ini->variable('MemcacheSettings', 'Host');
            $this->_port = $ini->variable('MemcacheSettings', 'Port');
        }
        elseif(    strpos(ini_get('session.save_handler'), 'memcache') === 0
                && preg_match('#^(?:tcp://)?(?P<memcacheHost>[^:]+):(?P<memcachePort>[^?]+)#', ini_get('session.save_path'), $m)
        ){
            // No memcache settings set, we try to use the session handler one
            $this->_host = $m['memcacheHost'];
            $this->_port = $m['memcachePort'];
        }

        if ( $this->_host )
        {
            if ( extension_loaded('memcached') )
            {
                $this->_memcache = new Memcached();
                $this->_type = self::TYPE_MEMCACHED;
                $this->_isValid = $this->_memcache->addserver( $this->_host, $this->_port );
            }
            elseif( extension_loaded( 'memcache') )
            {
                $this->_memcache = new Memcache();
                $this->_type = self::TYPE_MEMCACHE;
                $this->_isValid = $this->_memcache->connect( $this->_host, $this->_port );
            }
        }

        if ( !$this->isValid() )
        {
            eZDebug::writeError('Could not find any valid memcache configuration or memcache module', 'MemcacheTool');
            // do not break. Any memcache w/r should be fault tolerant in case memcache clears its cache by itself.
        }
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:41,代码来源:memcacheTool.php


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