當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。