本文整理汇总了PHP中Memcache::setCompressThreshold方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::setCompressThreshold方法的具体用法?PHP Memcache::setCompressThreshold怎么用?PHP Memcache::setCompressThreshold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::setCompressThreshold方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* Connects to the server
*
* @return boolean
*/
function connect()
{
if (!empty($this->config['servers'])) {
$persistant = isset($this->config['persistant']) ? (bool) $this->config['persistant'] : false;
foreach ((array) $this->config['servers'] as $server) {
list($ip, $port) = explode(':', $server);
$this->_memcache->addServer(trim($ip), (int) trim($port), $persistant);
}
} else {
return false;
}
if (!empty($this->config['compress_threshold'])) {
$this->_memcache->setCompressThreshold((int) $this->config['compress_threshold']);
}
return true;
}
示例2: Memcache
function __construct($host, $port = 11211)
{
$mc = new Memcache();
$mc->addServer($host, intval($port));
$mc->setCompressThreshold(self::CompressThreshold);
$this->_memcache = $mc;
}
示例3: initialize
protected function initialize($prefix, DataSourceMetaData $datasource = NULL) {
$result = TRUE;
if (class_exists('Memcache')) {
$this->memcache = new Memcache();
$successfulRegistrationCount = $unsuccessfulRegistrationCount = 0;
// adding servers
if (isset($datasource->host)) {
$serverResult = $this->registerServer($datasource->host, $datasource->port);
if ($serverResult) {
$successfulRegistrationCount++;
}
else {
$unsuccessfulRegistrationCount++;
}
}
if (isset($datasource->servers)) {
foreach ($datasource->servers as $server) {
$serverResult = $this->registerServer($server->host, $server->port);
if ($serverResult) {
$successfulRegistrationCount++;
}
else {
$unsuccessfulRegistrationCount++;
}
}
}
if ($successfulRegistrationCount == 0) {
$this->memcache = NULL;
}
else {
$this->memcache->setCompressThreshold(self::$DEFAULT__COMPRESSION_THRESHOLD, self::$DEFAULT__COMPRESSION_SAVINGS_MIN);
}
if ($unsuccessfulRegistrationCount > 0) {
$result = FALSE;
}
}
return $result;
}
示例4: _init
/**
* Starts the cache server connection
* Private method to call from other static methods of the class
*/
private static function _init()
{
if (self::$connected) {
return;
}
if (self::$driver == 'memcache') {
$conn = new Memcache();
$conn->connect(self::$host, self::$port);
$conn->setCompressThreshold(1000, 0.2);
self::$conn = $conn;
}
}
示例5: Memcache
/**
* constructor
*
* @param array $config
*/
function __construct($config)
{
parent::__construct($config);
$this->_memcache = new Memcache();
if (!empty($config['servers'])) {
$persistant = isset($config['persistant']) ? (bool) $config['persistant'] : false;
foreach ((array) $config['servers'] as $server) {
if (substr($server, 0, 5) == 'unix:') {
$this->_memcache->addServer(trim($server), 0, $persistant);
} else {
list($ip, $port) = explode(':', $server);
$this->_memcache->addServer(trim($ip), (int) trim($port), $persistant);
}
}
} else {
return false;
}
if (!empty($config['compress_threshold'])) {
$this->_memcache->setCompressThreshold((int) $config['compress_threshold']);
}
return true;
}
示例6: rs_memcache_init
function rs_memcache_init()
{
global $memcache;
global $memcacheservers;
//Set in config
if (!isset($memcache)) {
//Init cache instance on first hit
$memcache = new Memcache();
foreach ($memcacheservers as $server) {
$memcache->addServer($server);
}
$memcache->setCompressThreshold(1000, 0.2);
}
}
示例7: connect
protected function connect()
{
if (!isset($this->instance)) {
$this->memcache = new PhpMemcache();
$this->memcache->addServer($this->configuration['host'], $this->configuration['port']);
$status = @$this->memcache->getExtendedStats();
// unset $status[$server] or $status[$server] === false
if (empty($status[$this->server])) {
throw new Exception('Memcache connect failed about cache source "{0}"', [$this->source]);
}
// if ($this->memcache->getServerStatus($this->config['host'], $this->config['port']) === 0) {
// if ($this->config['pconnect'])
// $conn = @$this->memcache->pconnect($this->config['host'], $this->config['port']);
// else
// $conn = @$this->memcache->connect($this->config['host'], $this->config['port']);
// if ($conn === false)
// throw new Exception('Memcache connect failure about cache source "{0}"', [$this->name]);
// }
if ($this->configuration['compressThreshold'] > 0 && $this->configuration['compressRatio'] > 0) {
$this->memcache->setCompressThreshold($this->configuration['compressThreshold'], $this->configuration['compressRatio']);
}
}
return $this;
}
示例8: getMemcacheObj
/**
* Get memcache object
*
* @return object
*/
public function getMemcacheObj() {
static $memObj;
if(!$memObj){
if (!is_array($this->hosts) || empty($this->hosts)){
return null;
}
$memcache = new Memcache();
foreach($this->hosts as $host){
if(isset($host[1])){
$memcache->addServer($host[0], $host[1]);
} else {
$memcache->addServer($host[0], MEMSERVER_DEFAULT_PORT);
}
}
$memcache->setCompressThreshold(10000, 0.2);
$memObj = $memcache;
}
return $memObj;
}
示例9: getMcConnectionObj
public static function getMcConnectionObj()
{
static $memcache = NULL;
if (isset($memcache)) {
return $memcache;
}
//$memcache_servers = \OLOG\ConfWrapper::value(\OLOG\Model\ModelConstants::MODULE_CONFIG_ROOT_KEY . '.memcache_servers');
$memcache_servers = CacheConfig::getServersObjArr();
if (!$memcache_servers) {
return null;
}
// Memcached php extension not supported - slower, rare, extra features not needed
/** @var \Memcache $memcache */
$memcache = new \Memcache();
/** @var MemcacheServerSettings $server_settings_obj */
foreach ($memcache_servers as $server_settings_obj) {
\OLOG\Assert::assert($memcache->addServer($server_settings_obj->getHost(), $server_settings_obj->getPort()));
$memcache->setCompressThreshold(5000, 0.2);
}
return $memcache;
}
示例10: _init
/**
* Do initialization.
*
* @throws Horde_Memcache_Exception
*/
public function _init()
{
$this->_memcache = new Memcache();
for ($i = 0, $n = count($this->_params['hostspec']); $i < $n; ++$i) {
$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 (!empty($this->_params['c_threshold'])) {
$this->_memcache->setCompressThreshold($this->_params['c_threshold']);
}
// Force consistent hashing
ini_set('memcache.hash_strategy', 'consistent');
if (isset($this->_params['logger'])) {
$this->_logger = $this->_params['logger'];
$this->_logger->log('Connected to the following memcache servers:' . implode($this->_servers, ', '), 'DEBUG');
}
}
示例11: _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');
}
}
示例12: _getAllMemcache
/**
* 加载所有的memcache 服务
*/
private function _getAllMemcache()
{
$memcacheArray = array();
foreach ($this->_node as $key => $weight) {
list($host, $port) = explode(":", $key);
$_memcache_host_key = $host . '_' . $port;
if (!self::$_memcache[$_memcache_host_key]) {
$memcache = new Memcache();
if (!$memcache->connect($host, $port)) {
self::$_memcache[$_memcache_host_key] = '';
} else {
$memcache->setCompressThreshold(409600, 0.2);
self::$_memcache[$_memcache_host_key] = $memcache;
}
}
$memcacheArray[$_memcache_host_key] = self::$_memcache[$_memcache_host_key];
}
return $memcacheArray;
}
示例13: getResource
/**
* @return MemcacheSource
* @throws Exception\RuntimeException
*/
public function getResource()
{
if (!$this->resource) {
throw new Exception\RuntimeException('Memcache resource must be set');
}
if (!$this->resource instanceof MemcacheSource) {
$resource = new MemcacheSource();
if (!$resource->addserver($this->resource['host'], $this->resource['port'], $this->resource['persistent'], $this->resource['weight'])) {
throw new Exception\RuntimeException(sprintf('Cannot connect to memcache server on %s:%d', $this->resource['host'], $this->resource['port']));
}
$resource->setCompressThreshold(self::DEFAULT_COMPRESSTHRESHOLD);
$this->resource = $resource;
}
return $this->resource;
}
示例14: setResourceAutoCompressThreshold
/**
* Set compress threshold on a Memcache resource
*
* @param MemcacheResource $resource
* @param array $libOptions
*/
protected function setResourceAutoCompressThreshold(MemcacheResource $resource, $threshold, $minSavings)
{
if (!isset($threshold)) {
return;
}
if (isset($minSavings)) {
$resource->setCompressThreshold($threshold, $minSavings);
} else {
$resource->setCompressThreshold($threshold);
}
}
示例15: MCGet
<?php
$memcache = new Memcache();
if (!$memcache->connect('127.0.0.1', 11211)) {
DebugMessage('Cannot connect to memcached!', E_USER_ERROR);
}
$memcache->setCompressThreshold(50 * 1024);
function MCGet($key)
{
global $memcache;
return $memcache->get('rp_' . $key);
}
function MCSet($key, $val, $expire = 10800)
{
global $memcache;
return $memcache->set('rp_' . $key, $val, false, $expire);
}
function MCAdd($key, $val, $expire = 10800)
{
global $memcache;
return $memcache->add('rp_' . $key, $val, false, $expire);
}
function MCDelete($key)
{
global $memcache;
return $memcache->delete('rp_' . $key);
}