当前位置: 首页>>代码示例>>PHP>>正文


PHP Memcache::setCompressThreshold方法代码示例

本文整理汇总了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;
 }
开发者ID:TheReaCompany,项目名称:pooplog,代码行数:21,代码来源:Native.php

示例2: Memcache

 function __construct($host, $port = 11211)
 {
     $mc = new Memcache();
     $mc->addServer($host, intval($port));
     $mc->setCompressThreshold(self::CompressThreshold);
     $this->_memcache = $mc;
 }
开发者ID:JudonH,项目名称:writer,代码行数:7,代码来源:Memcached.php

示例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;
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:44,代码来源:MemcacheHandler.php

示例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;
     }
 }
开发者ID:Godefroy,项目名称:confeature,代码行数:16,代码来源:class.Cache.php

示例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;
 }
开发者ID:Creative-Srijon,项目名称:top10bestwp,代码行数:27,代码来源:Memcached.php

示例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);
    }
}
开发者ID:davidkeen,项目名称:railservice,代码行数:14,代码来源:route_service.php

示例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;
 }
开发者ID:janpoem,项目名称:kephp,代码行数:24,代码来源:Memcache.php

示例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;
 }
开发者ID:nopsky,项目名称:mbct,代码行数:24,代码来源:cache.class.php

示例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;
 }
开发者ID:o-log,项目名称:php-model,代码行数:21,代码来源:CacheMemcache.php

示例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');
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:28,代码来源:Memcache.php

示例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');
     }
 }
开发者ID:horde,项目名称:horde,代码行数:42,代码来源:Memcache.php

示例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;
 }
开发者ID:jesse108,项目名称:admin_base,代码行数:22,代码来源:Memcache.class.php

示例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;
 }
开发者ID:musicsnap,项目名称:Yaf.Global.Library,代码行数:19,代码来源:Memcache.php

示例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);
     }
 }
开发者ID:liuxuezhan,项目名称:my_tool,代码行数:17,代码来源:MemcacheResourceManager.php

示例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);
}
开发者ID:erorus,项目名称:realmpop,代码行数:27,代码来源:memcache.incl.php


注:本文中的Memcache::setCompressThreshold方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。