本文整理汇总了PHP中Memcached::getStats方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::getStats方法的具体用法?PHP Memcached::getStats怎么用?PHP Memcached::getStats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::getStats方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
}
示例2: __construct
/**
* @param array $servers List of servers
* @param int $expire Expiration time, defaults to 3600 seconds
* @throws \Exception
*/
public function __construct($servers = [], $expire = 3600)
{
// Set expiration time
$this->expire = $expire;
// Create memcached object
$this->cache = new \Memcached();
// Check if there already are servers added, according to the manual
// http://php.net/manual/en/memcached.addservers.php no duplication checks
// are made. Since we have at least one connection we don't need to add
// more servers and maybe add duplicates.
if (count($this->cache->getServerList()) === 0) {
// Add servers
$this->cache->addServers($servers);
}
// Get server stats
$stats = $this->cache->getStats();
// Loop through servers
foreach ($stats as $stat) {
// Check if pid is more than 0, if pid is -1 connection isn't working
if ($stat['pid'] > 0) {
// Return true to avoid the exception below
return true;
}
}
// If we end up here we don't have a working connection. Throw an exception that
// will be handled by the method calling this connect method. A working cache is
// NOT a requirement for the application to run so it's important to handle the
// exception and let the application run. Suggestion: if the exception below is
// thrown a new NullCache should be created
throw new \Exception('Unable to connect to Memcache(d) backend');
}
示例3: checkConnection
/**
* @return bool
*/
protected function checkConnection()
{
$stats = $this->cache->getStats();
$result = isset($stats[$this->configuration->getHost() . ":" . $this->configuration->getPort()]);
if (!$result) {
throw new CacheException('Connection error!');
}
return true;
}
示例4: status
/**
* @inheritdoc
*/
public function status()
{
$status_arr = $this->memcached->getStats();
$server_arr = $this->memcached->getServerList();
if (isset($server_arr[0]['host']) and isset($server_arr[0]['port']) and isset($status_arr["{$server_arr[0]['host']}:{$server_arr[0]['port']}"])) {
$info = $status_arr["{$server_arr[0]['host']}:{$server_arr[0]['port']}"];
} else {
$info = [];
}
$status[self::HITS] = isset($info['get_hits']) ? $info['get_hits'] : 0;
$status[self::MISSES] = isset($info['get_misses']) ? $info['get_misses'] : 0;
$status[self::START_TIME] = isset($info['uptime']) ? $info['uptime'] : 0;
$status[self::MEMORY_USED] = isset($info['bytes']) ? $info['bytes'] : 0;
$status[self::MEMORY_LEFT] = isset($info['limit_maxbytes']) ? $info['limit_maxbytes'] : 0;
return $status;
}
示例5: skipIfMemcacheIsNotRunning
private function skipIfMemcacheIsNotRunning(\Memcached $client)
{
$memcacheAddress = self::MEMCACHED_HOST . ':' . self::MEMCACHED_PORT;
if (!isset($client->getStats()[$memcacheAddress])) {
$this->markTestSkipped('You need a running memcached to run the integration tests!');
}
}
开发者ID:lizards-and-pumpkins,项目名称:lib-key-value-store-memcached,代码行数:7,代码来源:MemcachedKeyValueStoreTest.php
示例6: internalGetCapacity
/**
* Internal method to get storage capacity.
*
* @param array $normalizedOptions
* @return array|boolean Capacity as array or false on failure
* @throws Exception\ExceptionInterface
*/
protected function internalGetCapacity(array &$normalizedOptions)
{
$stats = $this->memcached->getStats();
if ($stats === false) {
throw $this->getExceptionByResultCode($this->memcached->getResultCode());
}
$mem = array_pop($stats);
return array('free' => $mem['limit_maxbytes'] - $mem['bytes'], 'total' => $mem['limit_maxbytes']);
}
示例7: serverStatistics
/**
* Get cache server statistics.
*
* @return array|string
* @access public
*/
public function serverStatistics()
{
if ($this->connected === true && $this->ping() === true) {
if ($this->isRedis === true) {
return $this->server->info();
} else {
return $this->server->getStats();
}
}
return array();
}
示例8: getStats
public function getStats($config)
{
if (!$config) {
return array();
}
$memcached = new \Memcached();
$memcached->setOption($memcached::OPT_PREFIX_KEY, $config['options']['namespace']);
$memcached->addServers($config['options']['servers']);
$stats = $memcached->getStats();
return $stats;
}
示例9: status
/**
* Get cache status
*
* @return array
*/
public function status()
{
if (!$this->isEnabled()) {
return array("provider" => "memcached", "enabled" => false, "objects" => null, "options" => array());
}
$stats = $this->instance->getStats();
$objects = 0;
foreach ($stats as $key => $value) {
$objects = max($objects, $value['curr_items']);
}
return array("provider" => "memcached", "enabled" => $this->isEnabled(), "objects" => intval($objects), "options" => $stats);
}
示例10: getStats
/**
* 获取服务器池的统计信息
* @param string $type
* @return array|bool
*/
public function getStats($type = "items")
{
switch ($this->client_type) {
case 'Memcache':
$stats = $this->m->getStats($type);
break;
default:
case 'Memcached':
$stats = $this->m->getStats();
break;
}
return $stats;
}
示例11: setUp
public function setUp()
{
if (!extension_loaded('memcached')) {
$this->markTestSkipped("Memcached extension not loaded");
}
// Ensure the proper configuration exists
$config = new \r8\Test\Config("MEMCACHE", array("HOST", "PORT"));
$config->test();
$cache = new \Memcached();
$cache->addServer(MEMCACHE_HOST, MEMCACHE_PORT);
if ($cache->getStats() === FALSE) {
$this->markTestSkipped("Unable to connect to Memcached server");
}
}
示例12: serverStatistics
/**
* Get cache server statistics.
*
* @return array
* @access public
*/
public function serverStatistics()
{
if ($this->ping()) {
switch (NN_CACHE_TYPE) {
case self::TYPE_REDIS:
return $this->server->info();
case self::TYPE_MEMCACHED:
return $this->server->getStats();
case self::TYPE_APC:
return apc_cache_info();
}
}
return array();
}
示例13: getMemcached
public function getMemcached()
{
try {
$m = new \Memcached();
$m->addServer(self::HOST, self::PORT);
$stats = $m->getStats();
$host = self::HOST . ':' . self::PORT;
if ($stats[$host]['pid'] == -1) {
throw new \Exception(sprintf('Unable to reach a memcached server on %s', $host));
}
} catch (\Exception $e) {
$this->markTestSkipped($e->getMessage());
}
return $m;
}
示例14: getCapacity
/**
* Get storage capacity.
*
* @param array $options
* @return array|boolean Capacity as array or false on failure
*
* @triggers getCapacity.pre(PreEvent)
* @triggers getCapacity.post(PostEvent)
* @triggers getCapacity.exception(ExceptionEvent)
*/
public function getCapacity(array $options = array())
{
$args = new ArrayObject(array('options' => &$options));
try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}
$mem = array_pop($this->memcached->getStats());
$result = array('free' => $mem['limit_maxbytes'] - $mem['bytes'], 'total' => $mem['limit_maxbytes']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
}
}
示例15: checkDriver
/**
* 检查连接状态
* @return boolean
*/
public function checkDriver()
{
if (!$this->isConnected && $this->reConnected < $this->maxReConnected) {
if ($this->handler->getStats() !== false) {
$this->isConnected = true;
} else {
$this->handler->initServers();
}
if (!$this->isConnected) {
$this->reConnected++;
} else {
$this->reConnected = 0;
}
}
return $this->isConnected;
}