本文整理汇总了PHP中Memcache::getExtendedStats方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::getExtendedStats方法的具体用法?PHP Memcache::getExtendedStats怎么用?PHP Memcache::getExtendedStats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::getExtendedStats方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStatsFromCache
function getStatsFromCache($type = 'sizes', $slabib = null, $limit = 100)
{
$ini = parse_ini_file('scielo.def', true);
$memcache = new Memcache();
$memcache->connect($ini['CACHE']['SERVER_CACHE'], $ini['CACHE']['SERVER_PORT_CACHE']);
if ($slabib != null) {
$arr = $memcache->getExtendedStats($type, $slabid, $limit);
} else {
$arr = $memcache->getExtendedStats($type);
}
$saida = '';
$arr = array_pop($arr);
$saida .= '<table border="1">';
foreach ($arr as $key => $value) {
$saida .= '<tr>';
$saida .= '<td>' . $key . '</td>';
if (is_array($value)) {
$saida .= '<td><table border="1">';
foreach ($value as $k => $v) {
$saida .= '<tr>';
$saida .= '<td>' . $k . '</td>';
$saida .= '<td>' . $v . '</td>';
$saida .= '</tr>';
}
$saida .= '</table></td>';
} else {
$saida .= '<td>' . $value . '</td>';
}
$saida .= '</tr>';
}
$saida .= '</table>';
$memcache->close();
return $saida;
}
示例2: getMemcacheKeys
function getMemcacheKeys()
{
$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211) or die("Could not connect to memcache server");
$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
$items = $memcache->getExtendedStats('items');
foreach ($allSlabs as $server => $slabs) {
foreach ($slabs as $slabId => $slabMeta) {
if (!is_numeric($slabId)) {
continue;
}
$cdump = $memcache->getExtendedStats('cachedump', (int) $slabId);
asort($cdump);
foreach ($cdump as $keys => $arrVal) {
if (!is_array($arrVal)) {
continue;
}
foreach ($arrVal as $k => $v) {
if (!$_GET['key'] || strpos($k, $_GET['key']) !== false) {
print "<tr><td>" . date('H:i:s d.m.Y', $v[1] + 108955) . "</td><td><a href='?key=" . $k . "'>" . $k . "</a></td><td>" . ($v[1] - time()) . "</td></tr>\n";
}
}
}
}
}
}
示例3: connect
/**
* Connect to the memcached pool
*
* @return void
*/
protected function connect()
{
$this->connected = false;
$this->memcache = new Memcache();
foreach ($this->pool as $host) {
$this->memcache->addServer($host['host'], $host['port'], true, $host['weight']);
// Confirm that at least one server in the pool connected
$stats = $this->memcache->getExtendedStats();
if ($this->connected || $stats["{$host['host']}:{$host['port']}"] !== false && sizeof($stats["{$host['host']}:{$host['port']}"]) > 0) {
$this->connected = true;
}
}
return $this->connected;
}
示例4: index
/**
* index - Just show the memcache server's statistics.
*
* @return void
**/
function index()
{
$this->auto_render = true;
$memcache_obj = new Memcache();
$memcache_obj->addServer(MEMCACHED_SERVER, MEMCACHED_SERVER_PORT);
$stats = $memcache_obj->getExtendedStats();
varDump($stats);
}
示例5: stats
/**
* Get stats about cluster
*
* @param bool $extended detailed stats?
* @return mixed - array on success; false on failure
**/
public function stats($extended = true)
{
if ($this->open()) {
if ($extended) {
return $this->memcache->getExtendedStats();
} else {
return $this->memcache->getStats();
}
}
return false;
}
示例6: checkMemcache
function checkMemcache()
{
$memCache = new \Memcache();
$memCache->addServer('127.0.0.1', 11211);
$stats = @$memCache->getExtendedStats();
$available = (bool) $stats['127.0.0.1:11211'];
if ($available && $memCache->connect('127.0.0.1', 11211) !== false) {
return true;
}
return false;
}
示例7: __construct
public function __construct()
{
$this->connect();
// Get keys (this code comes from Doctrine 2 project)
$this->keys = array();
$all_slabs = $this->memcache->getExtendedStats('slabs');
foreach ($all_slabs as $server => $slabs) {
if (is_array($slabs)) {
foreach (array_keys($slabs) as $slab_id) {
$dump = $this->memcache->getExtendedStats('cachedump', (int) $slab_id);
if ($dump) {
foreach ($dump as $entries) {
if ($entries) {
$this->keys = array_merge($this->keys, array_keys($entries));
}
}
}
}
}
}
}
示例8: 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;
}
示例9: __construct
/**
*
* @throws Exception
*/
protected function __construct()
{
if (!class_exists('Memcache', false)) {
throw new Exception('Class Memcache not Found. php5-memcache may not be installed.');
}
self::$_Connection = new Memcache();
foreach (self::$_MemCachePool as $_host => $weight) {
list($host, $port) = explode(":", $_host);
self::$_Connection->addServer($host, $port, true, $weight);
}
$results = @self::$_Connection->getExtendedStats();
foreach ($results as $__host => $_stats) {
if (empty($_stats)) {
list($host, $port) = explode(":", $__host);
self::$_Connection->setServerParams($host, $port, 1, -1, false);
Log::doLog("Server {$host}:{$port} down, not available.");
unset(self::$_MemCachePool[$__host]);
}
}
if (empty(self::$_MemCachePool)) {
throw new Exception('No Memcached servers available. All down.');
}
register_shutdown_function('MemcacheHandler::close');
}
示例10: _getCacheKeys
/**
* Fetch an array of all keys stored in cache
*
* @return array Returns the array of cache keys
*/
protected function _getCacheKeys()
{
$keys = array();
$allSlabs = $this->_memcache->getExtendedStats('slabs');
foreach ($allSlabs as $server => $slabs) {
foreach (array_keys($slabs) as $slabId) {
$dump = $this->_memcache->getExtendedStats('cachedump', (int) $slabId);
foreach ($dump as $entries) {
if ($entries) {
$keys = array_merge($keys, array_keys($entries));
}
}
}
}
return $keys;
}
示例11: getMemcacheConnection
/**
* Returns a Memcache connection.
*
* @param array $options Available options are 'host' and 'port'
*
* @return \Memcache
*
* @throws RuntimeException
*/
public function getMemcacheConnection(array $options = [])
{
$options = array_replace(['host' => 'localhost', 'port' => 11211], $options);
if (null !== ($cache = $this->getConnection('memcache', $options))) {
return $cache;
}
if (!extension_loaded('memcache')) {
throw new RuntimeException('The Memcache cache requires the Memcache extension.');
}
$memcache = new \Memcache();
$memcache->addServer($options['host'], $options['port']);
$key = sprintf("%s:%s", $options['host'], $options['port']);
$stats = @$memcache->getExtendedStats();
if (!isset($stats[$key]) || false === $stats[$key]) {
throw new RuntimeException(sprintf("Memcache instance with host '%s' and port '%s' is not reachable.", $options['host'], $options['port']));
}
return $this->setConnection('memcache', $options, $memcache);
}
示例12: check
/**
* @see ZendDiagnostics\CheckInterface::check()
*/
public function check()
{
if (!class_exists('Memcache', false)) {
return new Failure('Memcache extension is not loaded');
}
try {
$memcache = new \Memcache();
$memcache->addServer($this->host, $this->port);
$stats = @$memcache->getExtendedStats();
if (!$stats || !is_array($stats) || !isset($stats[$this->host . ':' . $this->port]) || $stats[$this->host . ':' . $this->port] === false) {
// Attempt a connection to make sure that the server is really down
if (!@$memcache->connect($this->host, $this->port)) {
return new Failure(sprintf('No memcache server running at host %s on port %s', $this->host, $this->port));
}
}
} catch (\Exception $e) {
return new Failure($e->getMessage());
}
return new Success(sprintf('Memcache server running at host %s on port %s', $this->host, $this->port));
}
示例13: cache_memcache_connect
function cache_memcache_connect()
{
#
# existing connection?
#
if ($GLOBALS['_cache_memcache_conn']) {
return $GLOBALS['_cache_memcache_conn'];
}
#
# set up a new one
#
$start = microtime_ms();
$memcache = new Memcache();
if (!$memcache) {
log_error("Failed to create Memcache object");
return null;
}
foreach ($GLOBALS['cfg']['memcache_pool'] as $bucket) {
@$memcache->addServer($bucket['host'], $bucket['port']);
}
$stats = $memcache->getExtendedStats();
foreach ($GLOBALS['cfg']['memcache_pool'] as $bucket) {
$key = implode(":", array_values($bucket));
if (!isset($stats[$key])) {
log_error("Failed to connect to {$key}");
return null;
}
if (!$stats[$key]['accepting_conns']) {
log_error("{$key} is not accepting connections");
return null;
}
}
$end = microtime_ms();
$time = $end - $start;
log_notice("cache", "connect to memcache {$host}:{$port} ({$time}ms)");
$GLOBALS['timings']['memcache_conns_count']++;
$GLOBALS['timings']['memcache_conns_time'] += $time;
$GLOBALS['_cache_memcache_conn'] = $memcache;
return $memcache;
}
示例14: getKeysList
/**
* Get array of cache item's keys
* @return array
*/
public function getKeysList()
{
$list = array();
$allSlabs = $this->memcache->getExtendedStats('slabs');
$items = $this->memcache->getExtendedStats('items');
foreach ($allSlabs as $server => $slabs) {
foreach ($slabs as $slabId => $slabMeta) {
if (!is_numeric($slabId)) {
continue;
}
$cdump = $this->memcache->getExtendedStats('cachedump', (int) $slabId, 1000000);
foreach ($cdump as $server => $entries) {
if ($entries) {
foreach ($entries as $eName => $eData) {
array_push($list, $eName);
}
}
}
}
}
ksort($list);
return $list;
}
示例15: clear
/**
* Delete all keys from the cache
*
* @param boolean $check If true no deletes will occur and instead CakePHP will rely
* on key TTL values.
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check)
{
if ($check) {
return true;
}
foreach ($this->_Memcache->getExtendedStats('slabs', 0) as $slabs) {
foreach (array_keys($slabs) as $slabId) {
if (!is_numeric($slabId)) {
continue;
}
foreach ($this->_Memcache->getExtendedStats('cachedump', $slabId, 0) as $stats) {
if (!is_array($stats)) {
continue;
}
foreach (array_keys($stats) as $key) {
if (strpos($key, $this->settings['prefix']) === 0) {
$this->_Memcache->delete($key);
}
}
}
}
}
return true;
}