本文整理汇总了PHP中Memcache::setOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::setOptions方法的具体用法?PHP Memcache::setOptions怎么用?PHP Memcache::setOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::setOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _init
/**
* Do initialization.
*
* @throws Horde_Memcache_Exception
*/
public function _init()
{
if (class_exists('Memcached')) {
if (empty($this->_params['persistent'])) {
$this->_memcache = new Memcached();
} else {
$this->_memcache = new Memcached('horde_memcache');
}
$this->_params['large_items'] = false;
$this->_memcache->setOptions(array(Memcached::OPT_COMPRESSION => $this->_params['compression'], Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT, Memcached::OPT_HASH => Memcached::HASH_MD5, Memcached::OPT_LIBKETAMA_COMPATIBLE => true, Memcached::OPT_PREFIX_KEY => $this->_params['prefix']));
} else {
// Force consistent hashing
ini_set('memcache.hash_strategy', 'consistent');
$this->_memcache = new Memcache();
}
for ($i = 0, $n = count($this->_params['hostspec']); $i < $n; ++$i) {
if ($this->_memcache instanceof Memcached) {
$res = $this->_memcache->addServer($this->_params['hostspec'][$i], empty($this->_params['port'][$i]) ? 0 : $this->_params['port'][$i], !empty($this->_params['weight'][$i]) ? $this->_params['weight'][$i] : 0);
} else {
$res = $this->_memcache->addServer($this->_params['hostspec'][$i], empty($this->_params['port'][$i]) ? 0 : $this->_params['port'][$i], !empty($this->_params['persistent']), !empty($this->_params['weight'][$i]) ? $this->_params['weight'][$i] : 1, 1, 15, true, array($this, 'failover'));
}
if ($res) {
$this->_servers[] = $this->_params['hostspec'][$i] . (!empty($this->_params['port'][$i]) ? ':' . $this->_params['port'][$i] : '');
}
}
/* Check if any of the connections worked. */
if (empty($this->_servers)) {
throw new Horde_Memcache_Exception('Could not connect to any defined memcache servers.');
}
if ($this->_memcache instanceof Memcache && !empty($this->_params['c_threshold'])) {
$this->_memcache->setCompressThreshold($this->_params['c_threshold']);
}
if (isset($this->_params['logger'])) {
$this->_logger = $this->_params['logger'];
$this->_logger->log('Connected to the following memcache servers:' . implode($this->_servers, ', '), 'DEBUG');
}
}