本文整理汇总了PHP中Memcached::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::setOption方法的具体用法?PHP Memcached::setOption怎么用?PHP Memcached::setOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::setOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param string $uniqId to be used to separate objects in addition to their key identifiers, for instance in a
* multi-user scenario.
*
* @return \iveeCrest\MemcachedWrapper
*/
public function __construct($uniqId)
{
$this->memcached = new \Memcached();
$this->memcached->addServer(Config::getCacheHost(), Config::getCachePort());
$this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, Config::getCachePrefix());
$this->uniqId = $uniqId;
}
示例2: __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
}
}
示例3: __construct
private function __construct()
{
$fristclassname = 'Memcached';
$secondclassname = 'Memcache';
$this->client_type = class_exists($fristclassname) ? $fristclassname : (class_exists($secondclassname) ? $secondclassname : FALSE);
if ($this->client_type) {
// 判断引入类型
switch ($this->client_type) {
case 'Memcached':
$this->m = new \Memcached('hella_connect');
if (count($this->m->getServerList()) == 0) {
$this->m->setOption(\Memcached::OPT_COMPRESSION, false);
// 关闭压缩功能
$this->m->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
// 使用binary二进制协议
} else {
// functionsDump ( $this->m->getServerList () );
}
break;
case 'Memcache':
$this->m = new \Memcache();
// if (auto_compress_tresh){
// $this->setcompressthreshold(auto_compress_tresh, auto_compress_savings);
// }
break;
}
$this->auto_connect();
} else {
echo 'ERROR: Failed to load Memcached or Memcache Class (∩_∩)';
exit;
}
}
示例4: __construct
protected function __construct()
{
if (class_exists('\\Memcached')) {
$m = new \Memcached("memcached_pool");
$m->setOption(\Memcached::OPT_BINARY_PROTOCOL, TRUE);
// some nicer default options
$m->setOption(\Memcached::OPT_NO_BLOCK, TRUE);
$m->setOption(\Memcached::OPT_AUTO_EJECT_HOSTS, TRUE);
// We use a consistent connection to memcached, so only add in the
// servers first time through otherwise we end up duplicating our
// connections to the server.
if (!$m->getServerList()) {
// parse server config
$servers = explode(",", MEMCACHE_SERVERS);
foreach ($servers as $s) {
$parts = explode(":", $s);
$m->addServer($parts[0], $parts[1]);
}
}
// setup authentication
if (defined('MEMCACHE_USERNAME') && defined('MEMCACHE_PASSWORD')) {
$m->setSaslAuthData(MEMCACHE_USERNAME, MEMCACHE_PASSWORD);
}
$this->memcache = $m;
}
}
示例5: getConnection
/**
* Create the Memcached connection
*
* @return void
*
* @since 12.1
* @throws RuntimeException
*/
protected function getConnection()
{
if (!static::isSupported()) {
throw new RuntimeException('Memcached Extension is not available');
}
$config = JFactory::getConfig();
$host = $config->get('memcached_server_host', 'localhost');
$port = $config->get('memcached_server_port', 11211);
// Create the memcached connection
if ($config->get('memcached_persist', true)) {
static::$_db = new Memcached($this->_hash);
$servers = static::$_db->getServerList();
if ($servers && ($servers[0]['host'] != $host || $servers[0]['port'] != $port)) {
static::$_db->resetServerList();
$servers = array();
}
if (!$servers) {
static::$_db->addServer($host, $port);
}
} else {
static::$_db = new Memcached();
static::$_db->addServer($host, $port);
}
static::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress);
$stats = static::$_db->getStats();
$result = !empty($stats["{$host}:{$port}"]) && $stats["{$host}:{$port}"]['pid'] > 0;
if (!$result) {
// Null out the connection to inform the constructor it will need to attempt to connect if this class is instantiated again
static::$_db = null;
throw new JCacheExceptionConnecting('Could not connect to memcached server');
}
}
示例6: init
public function init($config)
{
global $_G;
if (!$config) {
if (TAE) {
$config["host"] = "127.0.0.1";
$config["port"] = 11211;
} else {
$config = $_G['_config']['cache_config'];
}
}
$this->config = $config;
$connect = new Memcached();
//声明一个新的memcached链接
$connect->setOption(Memcached::OPT_COMPRESSION, false);
//关闭压缩功能
$connect->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
//使用binary二进制协议
$connect->addServer($config['host'], $config['port']);
//添加OCS实例地址及端口号
if ($config['username'] && $config['password']) {
//设置OCS帐号密码进行鉴权,如已开启免密码功能,则无需此步骤
$connect->setSaslAuthData($config['username'], $config['password']);
}
$this->enable = true;
$this->obj = $connect;
return $this->enable;
}
示例7: getConnection
/**
* Return memcached connection object
*
* @return object memcached connection object
*
* @since 12.1
*/
protected function getConnection()
{
if ((extension_loaded('memcached') && class_exists('Memcached')) != true) {
return false;
}
$config = JFactory::getConfig();
$this->_persistent = $config->get('memcache_persist', true);
$this->_compress = $config->get('memcache_compress', false) == false ? 0 : Memcached::OPT_COMPRESSION;
/*
* 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
if ($this->_persistent) {
$session = JFactory::getSession();
self::$_db = new Memcached($session->getId());
} else {
self::$_db = new Memcached();
}
$memcachedtest = self::$_db->addServer($server['host'], $server['port']);
if ($memcachedtest == false) {
return JError::raiseError(404, "Could not connect to memcached server");
}
self::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress);
// Memcached 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, 0);
}
return;
}
示例8: write
/**
* {@inheritdoc}
*/
public function write($key, $data, $expires = 60, $compressed = false)
{
$cmp = $this->driver->getOption(Memcached::OPT_COMPRESSION);
$this->driver->setOption(Memcached::OPT_COMPRESSION, $compressed);
$cached = $this->driver->set($key, $data, $expires);
$this->driver->setOption(Memcached::OPT_COMPRESSION, $cmp);
return $cached;
}
示例9: getBackend
protected function getBackend()
{
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);
$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$memcached->setOption(Memcached::OPT_TCP_NODELAY, true);
return Matryoshka\Memcached::create($memcached);
}
示例10: __construct
/**
* Constructor
* @param array $options cache store storage option
*/
public function __construct($options = array())
{
$this->connect = new \Memcached();
$this->prefix = $options['prefix'];
$this->default_ttl = $options['default_ttl'];
$this->connect->setOption(\Memcached::OPT_PREFIX_KEY, $this->prefix);
$this->connect->addServers($options['servers']);
}
示例11: connect
/**
* {@inheritdoc}
*/
public function connect()
{
foreach ($this->options['options'] as $option => $value) {
$this->service->setOption($option, $value);
}
foreach ($this->options['servers'] as $server) {
$server = $server + $this->options['defaultServer'];
$this->service->addServer($server['host'], $server['port'], $server['weight']);
}
}
示例12: __construct
/**
* @param $persistentId
* @param array $connections
*/
public function __construct($persistentId, array $connections)
{
$this->isMemcachedExtensionAvailable();
$this->memcached = new MemcachedDriver($persistentId);
$this->memcached->addServers($connections);
$this->memcached->setOption(MemcachedDriver::OPT_SERIALIZER, \defined(MemcachedDriver::HAVE_IGBINARY) && MemcachedDriver::HAVE_IGBINARY ? MemcachedDriver::SERIALIZER_IGBINARY : MemcachedDriver::SERIALIZER_PHP);
$this->memcached->setOption(MemcachedDriver::OPT_DISTRIBUTION, MemcachedDriver::DISTRIBUTION_CONSISTENT);
$this->memcached->setOption(MemcachedDriver::OPT_LIBKETAMA_COMPATIBLE, true);
$this->memcached->setOption(MemcachedDriver::OPT_BINARY_PROTOCOL, true);
}
示例13: __construct
public function __construct()
{
$this->connect();
if ($this->is_connected) {
$this->memcached->setOption(Memcached::OPT_PREFIX_KEY, _DB_PREFIX_);
if ($this->memcached->getOption(Memcached::HAVE_IGBINARY)) {
$this->memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY);
}
}
}
示例14: __construct
/**
* Constructor.
*
* @param \Memcached $memcached A \Memcached instance
* @param array $memcachedOptions An associative array of Memcached options
* @param array $options Session configuration options.
*/
public function __construct(\Memcached $memcached, array $memcachedOptions = array(), array $options = array())
{
$this->memcached = $memcached;
// defaults
if (!isset($memcachedOptions['serverpool'])) {
$memcachedOptions['serverpool'][] = array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 1);
}
$memcachedOptions['expiretime'] = isset($memcachedOptions['expiretime']) ? (int) $memcachedOptions['expiretime'] : 86400;
$this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, isset($memcachedOptions['prefix']) ? $memcachedOptions['prefix'] : 'sf2s');
$this->memcachedOptions = $memcachedOptions;
}
示例15: init
public function init()
{
$this->parentInit();
if (!$this->storage instanceof \Memcached) {
$this->storage = new \Memcached();
$this->normalizeServers($this->servers, $this->storage);
$this->storage->setOption(\Memcached::OPT_COMPRESSION, true);
}
if ($this->serializer !== self::SERIALIZE_JSON) {
$this->storage->setOption(\Memcached::OPT_SERIALIZER, \Memcached::SERIALIZER_PHP);
}
}