本文整理汇总了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}");
}
}
}
示例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)));
}
}
示例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);
}
示例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)
});
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}