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


PHP Memcached::setOptions方法代码示例

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


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

示例1: __construct

 public function __construct($prefix = '')
 {
     parent::__construct($prefix);
     if (is_null(self::$cache)) {
         self::$cache = new \Memcached();
         $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers');
         if (!$servers) {
             $server = \OC::$server->getSystemConfig()->getValue('memcached_server');
             if ($server) {
                 $servers = array($server);
             } else {
                 $servers = array(array('localhost', 11211));
             }
         }
         self::$cache->addServers($servers);
         $defaultOptions = [\Memcached::OPT_CONNECT_TIMEOUT => 50, \Memcached::OPT_RETRY_TIMEOUT => 50, \Memcached::OPT_SEND_TIMEOUT => 50, \Memcached::OPT_RECV_TIMEOUT => 50, \Memcached::OPT_POLL_TIMEOUT => 50, \Memcached::OPT_COMPRESSION => true, \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, \Memcached::OPT_BINARY_PROTOCOL => true];
         // by default enable igbinary serializer if available
         if (\Memcached::HAVE_IGBINARY) {
             $defaultOptions[\Memcached::OPT_SERIALIZER] = \Memcached::SERIALIZER_IGBINARY;
         }
         $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []);
         if (is_array($options)) {
             $options = $options + $defaultOptions;
             self::$cache->setOptions($options);
         } else {
             throw new HintException("Expected 'memcached_options' config to be an array, got {$options}");
         }
     }
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:29,代码来源:Memcached.php

示例2: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     self::$memcached = new \Memcached();
     self::$memcached->setOptions(array(\Memcached::OPT_TCP_NODELAY => true, \Memcached::OPT_NO_BLOCK => true, \Memcached::OPT_CONNECT_TIMEOUT => 1000));
     if (count(self::$memcached->getServerList()) == 0) {
         self::$memcached->addServers(array(array(MEMCACHED_HOST, MEMCACHED_PORT)));
     }
 }
开发者ID:fustundag,项目名称:tokenbucket,代码行数:8,代码来源:MemcachedTest.php

示例3: setOptions

 /**
  * Configure options
  *
  * @return void
  */
 protected function setOptions()
 {
     $options = $this->defaultOptions;
     if (array_key_exists('options', $this->config)) {
         $options = array_merge($options, $this->config['options']);
     }
     $this->connection->setOptions($options);
 }
开发者ID:itkg,项目名称:core,代码行数:13,代码来源:Memcached.php

示例4: __construct

    /**
     * Constructor
     *
     * @param  null|array|Traversable|MemcachedOptions $options
     * @throws Exception\ExceptionInterface
     * @return void
     */
    public function __construct($options = null)
    {
        if (static::$extMemcachedMajorVersion === null) {
            $v = (string) phpversion('memcached');
            static::$extMemcachedMajorVersion = ($v !== '') ? (int)$v[0] : 0;
        }

        if (static::$extMemcachedMajorVersion < 1) {
            throw new Exception\ExtensionNotLoadedException('Need ext/memcached version >= 1.0.0');
        }

        parent::__construct($options);

        // It's ok to init the memcached instance as soon as possible because
        // ext/memcached auto-connects to the server on first use
        $this->memcached = new MemcachedResource();
        $options = $this->getOptions();

        // set lib options
        if (static::$extMemcachedMajorVersion > 1) {
            $this->memcached->setOptions($options->getLibOptions());
        } else {
            foreach ($options->getLibOptions() as $k => $v) {
                $this->memcached->setOption($k, $v);
            }
        }

        $servers = $options->getServers();
        if (!$servers) {
            $options->addServer('127.0.0.1', 11211);
            $servers = $options->getServers();
        }
        $this->memcached->addServers($servers);

        // get notified on change options
        $memc   = $this->memcached;
        $memcMV = static::$extMemcachedMajorVersion;
        $this->events()->attach('option', function ($event) use ($memc, $memcMV) {
            $params = $event->getParams();

            if (isset($params['lib_options'])) {
                if ($memcMV > 1) {
                    $memc->setOptions($params['lib_options']);
                } else {
                    foreach ($params['lib_options'] as $k => $v) {
                        $memc->setOption($k, $v);
                    }
                }
            }

            // TODO: update on change/add server(s)
        });
    }
开发者ID:necrogami,项目名称:zf2,代码行数:60,代码来源:Memcached.php

示例5: getHandler

 /**
  * Get Mamcached Handler
  *
  * @return \Memcached
  */
 public function getHandler()
 {
     if (!$this->handler) {
         $persistentId = isset($this->settings['persistent']) ? $this->settings['persistent'] : null;
         $this->handler = new \Memcached($persistentId);
         if (!$this->handler->getServerList()) {
             $this->handler->addServers($this->settings['servers']);
         }
         if (isset($this->settings['options'])) {
             $this->handler->setOptions($this->settings['options']);
         }
     }
     return $this->handler;
 }
开发者ID:Kit-kat1,项目名称:custom-bluz-app,代码行数:19,代码来源:Memcached.php

示例6: open

 public function open($savePath, $sessID)
 {
     $options = [\Memcached::OPT_CONNECT_TIMEOUT => $this->timeout, \Memcached::OPT_DISTRIBUTION, \Memcached::DISTRIBUTION_CONSISTENT];
     $this->handle = new \Memcached();
     $this->handle->setOptions($options);
     if (isset($this->servers['host'])) {
         $this->handle->addServer($this->servers['host'], $this->servers['port'], isset($this->servers['weight']) ? $this->servers['weight'] : null);
     } else {
         foreach ($this->servers as $server) {
             $this->handle->addServer($server['host'], $server['port'], isset($server['weight']) ? $server['weight'] : null);
         }
     }
     return true;
 }
开发者ID:dongnan,项目名称:LinkTool,代码行数:14,代码来源:Memcached.class.php

示例7: setTimeout

 /**
  * @param float $requestTimeout time in seconds
  *
  * @return PeclMemcached
  */
 public function setTimeout($requestTimeout)
 {
     $this->ensureTriedToConnect();
     $this->requestTimeout = $requestTimeout;
     $this->instance->setOptions([\Memcached::OPT_SEND_TIMEOUT => $requestTimeout * 1000, \Memcached::OPT_RECV_TIMEOUT => $requestTimeout * 1000]);
     return $this;
 }
开发者ID:justthefish,项目名称:hesper,代码行数:12,代码来源:PeclMemcached.php

示例8: addOptions

 /**
  * @param \Memcached $memcached
  * @return $this
  */
 private function addOptions(\Memcached $memcached)
 {
     if (is_array($this->options) && !empty($this->options)) {
         foreach ($this->options as $option) {
             $memcached->setOption(constant('\\Memcached::' . $option[MemcacheConfigConstants::OPTION_NAME]), $option[MemcacheConfigConstants::OPTION_VALUE]);
         }
         $memcached->setOptions($this->options);
     }
     return $this;
 }
开发者ID:null9beta,项目名称:php-memcache-viewer,代码行数:14,代码来源:AbstractMemcacheConfig.php

示例9: initServers

 /**
  * 初始化servers
  */
 private function initServers()
 {
     if (empty($this->config['servers'])) {
         $servers = [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 1]];
     } else {
         $servers = $this->config['servers'];
     }
     foreach ($servers as $server) {
         $host = isset($server['host']) ? $server['host'] : '127.0.0.1';
         $port = isset($server['port']) ? $server['port'] : 11211;
         $weight = isset($server['weight']) ? $server['weight'] : 0;
         $this->servers["{$host}:{$port}"] = [$host, $port, $weight];
         $this->handler->addserver($host, $port, $weight);
     }
     if (!empty($this->config['options'])) {
         $this->handler->setOptions($this->config['options']);
     }
     $this->handler->getStats();
 }
开发者ID:iliubang,项目名称:LinkCache,代码行数:22,代码来源:Memcached.php

示例10: getMemcached

 /**
  * @return \Memcached
  * @throws InvalidConfigException
  */
 public function getMemcached()
 {
     if (null === $this->instance) {
         if (!extension_loaded('memcached')) {
             throw new InvalidConfigException(__CLASS__ . ' requires PHP `memcached` extension to be loaded.');
         }
         $this->instance = new \Memcached($this->persistentId);
         // SASL authentication
         // @see http://php.net/manual/en/memcached.setsaslauthdata.php
         if (ini_get('memcached.use_sasl') && (null !== $this->username || null !== $this->password)) {
             if (method_exists($this->instance, 'setSaslAuthData')) {
                 $this->instance->setSaslAuthData($this->username, $this->password);
             }
         }
         if (!empty($this->options)) {
             $this->instance->setOptions($this->options);
         }
     }
     return $this->instance;
 }
开发者ID:hitmeister,项目名称:rapido-cache,代码行数:24,代码来源:MemcachedCache.php

示例11: getConfiguredDriver

 protected function getConfiguredDriver(array $config)
 {
     $memcached = new \Memcached();
     foreach ($config[Config::INDEX_SERVERS] as $server) {
         $memcached->addServer($server[Config::INDEX_HOST], $server[Config::INDEX_PORT]);
     }
     if (!empty($config[Config::INDEX_OPTIONS])) {
         $memcached->setOptions($config[Config::INDEX_OPTIONS]);
     }
     return $memcached;
 }
开发者ID:dgreda,项目名称:cache-factory,代码行数:11,代码来源:Memcached.php

示例12: __construct

 /**
  * @param FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = array())
 {
     $this->_backend = new MemcachedDriver(self::DRIVER_PERSISTENCE_ID);
     if (!isset($options['servers'])) {
         $options['servers'] = array(array('host' => self::DEFAULT_HOST));
     }
     foreach ($options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = self::DEFAULT_PORT;
         }
         if (!array_key_exists('weight', $server)) {
             $server['weight'] = self::DEFAULT_WEIGHT;
         }
         $this->_backend->addServer($server['host'], $server['port'], $server['weight']);
     }
     if (isset($options['client']) && is_array($options['client'])) {
         $this->_backend->setOptions($options['client']);
     }
     unset($options['servers'], $options['client']);
     parent::__construct($frontend, $options);
 }
开发者ID:aisuhua,项目名称:vkplay,代码行数:25,代码来源:Memcached.php

示例13: __invoke

 /**
  * @param ContainerInterface $container
  * @return MemcachedSnapshotAdapter
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->get('config');
     $config = $this->options($config)['snapshot_adapter']['options'];
     if (isset($config['memcached_connection_alias'])) {
         $memcached = $container->get($config['memcached_connection_alias']);
     } else {
         $memcached = new \Memcached($config['persistent_id']);
         $memcached->addServers($config['servers']);
         $memcached->setOptions($config['memcached_options']);
     }
     return new MemcachedSnapshotAdapter($memcached);
 }
开发者ID:prolic,项目名称:snapshot-memcached-adapter,代码行数:17,代码来源:MemcachedSnapshotAdapterFactory.php

示例14: initServers

 /**
  * 初始化servers
  */
 private function initServers()
 {
     if (empty($this->config['servers'])) {
         $servers = [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 1]];
     } else {
         $servers = $this->config['servers'];
     }
     foreach ($servers as $server) {
         $host = isset($server['host']) ? $server['host'] : '127.0.0.1';
         $port = isset($server['port']) ? $server['port'] : 11211;
         $weight = isset($server['weight']) ? $server['weight'] : 0;
         $this->handler->addserver($host, $port, $weight);
     }
     if (!empty($this->config['options'])) {
         $this->handler->setOptions($this->config['options']);
     }
     //如果获取服务器池的统计信息返回false,说明服务器池中有不可用服务器
     if ($this->handler->getStats() === false) {
         $this->isConnected = false;
     } else {
         $this->isConnected = true;
     }
 }
开发者ID:shitfSign,项目名称:LinkCache,代码行数:26,代码来源:Memcached.php

示例15: connect

 /**
  * 连接memcached
  *
  * @return \Memcached
  */
 public function connect()
 {
     if ($this->handler) {
         return $this->handler;
     }
     $servers = isset($this->config['servers']) ? $this->config['servers'] : array(array('127.0.0.1', 11211));
     $handler = new \Memcached();
     if (!$handler->addServers($servers)) {
         throw new \Lysine\Service\ConnectionException('Cannot connect memcached');
     }
     if (isset($config['options'])) {
         $handler->setOptions($config['options']);
     }
     return $this->handler = $handler;
 }
开发者ID:lryl,项目名称:Lysine2,代码行数:20,代码来源:memcached.php


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