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;
}
Exemple #2
0
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";
                    }
                }
            }
        }
    }
}
 /**
  * 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;
 }
 /**
  * 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);
 }
Exemple #5
0
 /**
  * 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;
 }
 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;
 }
Exemple #7
0
 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));
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #8
0
 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;
 }
 /**
  *
  * @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');
 }
Exemple #10
0
 /**
  * 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;
 }
 /**
  * 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);
 }
Exemple #12
0
 /**
  * @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));
 }
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;
}
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Returns size used by cache
  */
 public function get_stats_size($timeout_time)
 {
     $size = array('bytes' => 0, 'items' => 0, 'timeout_occurred' => false);
     $key_prefix = $this->get_item_key('');
     $slabs = @$this->_memcache->getExtendedStats('slabs');
     $slabs_plain = array();
     if (is_array($slabs)) {
         foreach ($slabs as $server => $server_slabs) {
             foreach ($server_slabs as $slab_id => $slab_meta) {
                 if ((int) $slab_id > 0) {
                     $slabs_plain[(int) $slab_id] = '*';
                 }
             }
         }
     }
     foreach ($slabs_plain as $slab_id => $nothing) {
         $cdump = @$this->_memcache->getExtendedStats('cachedump', (int) $slab_id);
         if (!is_array($cdump)) {
             continue;
         }
         foreach ($cdump as $server => $keys_data) {
             if (!is_array($keys_data)) {
                 continue;
             }
             foreach ($keys_data as $key => $size_expiration) {
                 if (substr($key, 0, strlen($key_prefix)) == $key_prefix) {
                     if (count($size_expiration) > 0) {
                         $size['bytes'] += $size_expiration[0];
                         $size['items']++;
                     }
                 }
             }
         }
     }
     return $size;
 }
 /**
  * Get all cache keys on a server
  *
  * @since 2.0.0
  *
  * @param  string $server
  * @param  int    $port
  *
  * @return array
  */
 public function retrieve_keys($server, $port = 11211)
 {
     // Connect to Memcache
     $memcache = new Memcache();
     $memcache->connect($server, $port);
     // No errors
     $old_errors = error_reporting(0);
     // Get slabs
     $slabs = $memcache->getExtendedStats('slabs');
     $list = array();
     // Loop through servers to get slabs
     foreach ($slabs as $server => $slabs) {
         // Loop through slabs to target single slabs
         foreach (array_keys($slabs) as $slab_id) {
             // Skip if slab ID is empty
             if (empty($slab_id)) {
                 continue;
             }
             // Get the entire slab
             $cache_dump = $memcache->getExtendedStats('cachedump', (int) $slab_id);
             // Loop through slab to find keys
             foreach ($cache_dump as $slab_dump) {
                 // Skip if key isn't an array (how'd that happen?)
                 if (!is_array($slab_dump)) {
                     continue;
                 }
                 // Loop through keys and add to list
                 foreach (array_keys($slab_dump) as $k) {
                     $list[] = $k;
                 }
             }
         }
     }
     // Restore error reporting
     error_reporting($old_errors);
     // Return the list of Memcache server slab keys
     return $list;
 }
<?php

//
// Looks up and reports on both memcache server stats. Must be run on spare
// host since it's the only one with the Memcache pecl package installed.
//
require_once 'commandLine.inc';
$memcache = new Memcache();
$s1 = split(':', WH_MEMCACHED_SERVER_1);
$memcache->connect($s1[0], $s1[1]);
$s2 = split(':', WH_MEMCACHED_SERVER_2);
$memcache->connect($s2[0], $s2[1]);
print_r($memcache->getExtendedStats());
Exemple #19
0
 public function getMemStats()
 {
     $memcache = new Memcache();
     $memcache->connect('localhost', 11211);
     return $memcache->getExtendedStats();
 }
Exemple #20
0
            $jsonreads = $runname . "bases";
            $json_test = $memcache->get($jsonreads);
            echo $jsonreads . "<br>";
            echo "{$json_test}<br>";
        }
    }
}
?>
							                <?php 
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
echo '<pre>';
//echo "Hello";
$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
$items = $memcache->getExtendedStats('items');
foreach ($allSlabs as $server => $slabs) {
    foreach ($slabs as $slabId => $slabMeta) {
        $cdump = $memcache->getExtendedStats('cachedump', (int) $slabId);
        foreach ($cdump as $keys => $arrVal) {
            if (!is_array($arrVal)) {
                continue;
            }
            foreach ($arrVal as $k => $v) {
                echo $k . '<br>';
            }
        }
    }
}
echo '</pre>';
Exemple #21
0
 *
 * @author    Kezhao Pan <*****@*****.**>
 * @link      https://github.com/42Team-itslove/passport
 * @license   https://github.com/42Team-itslove/passport/blob/master/LICENSE
 * @copyright (c) 2003 - 2014 42Team
 */
/**
 * 显示本地服务器Memcache中的所有Key
 */
echo "Local Memcached: See\n\n";
if (!in_array('memcache', get_loaded_extensions())) {
    die('  Memcache Extension No Load');
}
$mem = new Memcache();
$mem->addserver('localhost', 11211, 1, 1, 300);
$items = $mem->getExtendedStats('items')['localhost:11211']['items'];
$keys_container = array();
if (!is_array($items) || empty($items)) {
    echo "There are no any key \n\n";
    exit;
}
foreach ($items as $key => $values) {
    $id = $key;
    $str = $mem->getExtendedStats("cachedump", $id, 0);
    $line = $str['localhost:11211'];
    if (is_array($line) && count($line) > 0) {
        foreach (array_keys($line) as $key) {
            $keys_container[] = $key;
        }
    }
}
Exemple #22
0
 public function vxStatus()
 {
     echo '<div id="main">';
     echo '<div class="blank">';
     _v_ico_map();
     echo ' <a href="/">' . Vocabulary::site_name . '</a> &gt; ' . $this->lang->system_status() . '</div>';
     echo '<div class="blank" align="left">';
     _v_ico_silk('group');
     echo ' 每月新注册用户数量';
     _v_hr();
     require_once BABEL_PREFIX . '/res/chart_user_month.php';
     echo '</div>';
     echo '<div class="blank" align="left">';
     _v_ico_silk('table_multiple');
     echo ' 每月新主题数量';
     _v_hr();
     require_once BABEL_PREFIX . '/res/chart_topic_month.php';
     echo '</div>';
     echo '<div class="blank" align="left">';
     _v_ico_silk('comments');
     echo ' 每月新回复数量';
     _v_hr();
     require_once BABEL_PREFIX . '/res/chart_post_month.php';
     echo '</div>';
     echo '<div class="blank" align="left">';
     _v_ico_silk('chart_bar');
     echo ' 主题分布';
     _v_hr();
     require_once BABEL_PREFIX . '/res/chart_topic_node.php';
     echo '</div>';
     echo '<div class="blank" align="left">';
     _v_ico_silk("information");
     echo ' ' . Vocabulary::term_status;
     $rs = mysql_query('SHOW STATUS', $this->db);
     $status = array();
     while ($row = mysql_fetch_assoc($rs)) {
         $status[$row['Variable_name']] = $row['Value'];
     }
     mysql_free_result($rs);
     $rs = mysql_query('SHOW VARIABLES', $this->db);
     while ($row = mysql_fetch_assoc($rs)) {
         $status[$row['Variable_name']] = $row['Value'];
     }
     mysql_free_result($rs);
     if ($_SESSION['babel_ua']['GECKO_DETECTED'] || $_SESSION['babel_ua']['KHTML_DETECTED'] || $_SESSION['babel_ua']['OPERA_DETECTED']) {
         $hack_width = 'width="100%" ';
     } else {
         $hack_width = 'width="99%" ';
     }
     echo '<table ' . $hack_width . 'cellpadding="0" cellspacing="0" border="0" class="fav">';
     echo '<tr><td colspan="2" align="left" class="section_even">';
     _v_ico_silk('computer');
     echo ' <small><strong>Your User Agent</strong>: ' . $_SERVER['HTTP_USER_AGENT'] . '</small>';
     _v_hr();
     _v_ico_silk('cog');
     echo ' <small><strong>Parsed As</strong>: ' . $_SESSION['babel_ua']['name'] . '/' . $_SESSION['babel_ua']['version'] . ' on ' . $_SESSION['babel_ua']['platform'] . '</small>';
     echo '</td></tr>';
     echo '<tr><td colspan="2" align="left"><div class="notify">';
     $flag_win = false;
     $flag_linux = false;
     if (strtolower(PHP_OS) == 'winnt') {
         $platform = 'Windows NT';
         $flag_win = true;
     } else {
         $platform = shell_exec('uname -s');
         if (preg_match('/linux/i', $platform)) {
             $flag_linux = true;
         }
     }
     if ($flag_linux) {
         _v_ico_silk('tux');
     } else {
         _v_ico_silk('server');
     }
     echo ' 基础架构 ' . $platform;
     echo '</div></td></tr>';
     echo '<tr><td colspan="2" align="left" class="section_even"><small><strong>OS</strong>: ';
     echo $flag_win ? 'Windows NT' : shell_exec('uname -a');
     echo '</small></td></tr>';
     echo '<tr><td colspan="2" align="left" class="section_odd"><small><strong>Machine Architecture</strong>: ';
     echo $flag_win ? 'x86' : shell_exec('uname -m');
     echo '</small></td></tr>';
     echo '<tr><td colspan="2" align="left" class="section_even"><small><strong>Uptime</strong>: ';
     echo $flag_win ? 'unknown' : shell_exec('uptime');
     echo '</small></td></tr>';
     echo '<tr><td colspan="2" align="left" class="section_odd"><small><strong>Server Memory Usage</strong>: ';
     if (strtolower(PHP_OS) == 'linux') {
         $mem_info = get_mem_info();
         $mem_percent = $mem_info['used'] / $mem_info['total'];
         $mem_width = floor(400 * $mem_percent);
         echo $mem_info['used'] . ' kB / ' . $mem_info['total'] . ' kB';
         echo '<div style="-moz-border-radius: 5px; margin-top: 10px; width: 400px; padding: 2px; border: 1px solid #CCC;">';
         echo '<div style="width: ' . $mem_width . 'px; height: 10px; background-color: #33F; background-image: url(' . "'/img/fall_sky.gif'" . ')"></div>';
         echo '</div>';
     } else {
         echo 'unknown';
     }
     echo '</small></td></tr>';
     if (function_exists('apache_get_version')) {
         echo '<tr><td colspan="2" align="left"><div class="notify">';
         _v_ico_silk('server_link');
         echo ' 应用程序服务器子系统 Apache Web Server';
         echo '</div></td></tr>';
         echo '<tr><td colspan="2" align="left" class="section_even"><small><strong>Version</strong>: ';
         echo apache_get_version();
         echo '</td></tr>';
         $_modules = apache_get_modules();
         echo '<tr><td colspan="2" align="left" class="section_even"><small><strong>Modules</strong>: ';
         _v_ico_silk('bullet_black');
         echo ' important module';
         echo ' &nbsp; ';
         _v_ico_silk('bullet_blue');
         echo ' regular module';
         echo '<blockquote>';
         foreach ($_modules as $module) {
             if (in_array($module, array('mod_rewrite', 'mod_php5'))) {
                 _v_ico_silk('bullet_black');
             } else {
                 _v_ico_silk('bullet_blue');
             }
             echo ' ' . $module . '<br />';
         }
         echo '</blockquote>';
         echo '</td></tr>';
     }
     echo '<tr><td colspan="2" align="left"><div class="notify">';
     _v_ico_silk('database');
     echo ' 数据库子系统 MySQL ' . mysql_get_server_info($this->db) . '</div></td></tr>';
     echo '<tr><td colspan="2" align="left"><span class="tip">数据库系统信息</span></td></tr>';
     echo '<tr><td width="150" align="right" class="section_even">服务器字符集</td><td class="section_even">' . $status['collation_server'] . '</td></tr>';
     echo '<tr><td width="150" align="right" class="section_odd">当前数据库字符集</td><td class="section_odd">' . $status['collation_database'] . '</td></tr>';
     echo '<tr><td width="150" align="right" class="section_even">运转时间</td><td class="section_even">' . $status['Uptime'] . ' 秒';
     if ($status['Uptime'] > 86400) {
         echo '(' . intval($status['Uptime'] / 86400) . ' 天)';
     }
     echo '</td></tr>';
     echo '<tr><td colspan="2" align="left"><span class="tip">性能数据</span></td></tr>';
     echo '<tr><td width="150" align="right" class="section_even">线程创建数量</td><td width="auto" class="section_even">' . $status['Threads_created'] . '(每分钟 ';
     printf("%.2f", $status['Threads_created'] / ($status['Uptime'] / 60));
     echo ')</td></tr>';
     echo '<tr><td width="150" align="right" class="section_odd">已处理的查询数量</td><td width="auto" class="section_odd">' . $status['Questions'] . '(每分钟 ';
     printf("%.2f", $status['Questions'] / ($status['Uptime'] / 60));
     echo ')</td></tr>';
     echo '<tr><td width="150" align="right" class="section_even">可用缓存内存</td><td width="auto" class="section_even">';
     printf("%dKB", floatval($status['Qcache_free_memory'] / 1024));
     echo '</td></tr>';
     echo '<tr><td width="150" align="right" class="section_odd">缓存中的查询数据</td><td width="auto" class="section_odd">' . $status['Qcache_queries_in_cache'] . '</td></tr>';
     echo '<tr><td width="150" align="right" class="section_even">插入缓存的查询数量</td><td width="auto" class="section_even">' . $status['Qcache_inserts'] . '(每分钟 ';
     printf("%.2f", $status['Qcache_inserts'] / ($status['Uptime'] / 60));
     echo ')</td></tr>';
     echo '<tr><td width="150" align="right" class="section_odd">命中缓存的查询数量</td><td width="auto" class="section_odd">' . $status['Qcache_hits'] . '(每分钟 ';
     printf("%.2f", $status['Qcache_hits'] / ($status['Uptime'] / 60));
     echo ')</td></tr>';
     echo '<tr><td width="150" align="right" class="section_even">无法缓存的查询数量</td><td width="auto" class="section_even">' . $status['Qcache_not_cached'] . '(每分钟 ';
     printf("%.2f", $status['Qcache_not_cached'] / ($status['Uptime'] / 60));
     echo ')</td></tr>';
     echo '<tr><td width="150" align="right" class="section_odd">缓存命中率</td><td width="auto" class="section_odd">';
     printf("%.3f%%", $status['Qcache_hits'] / $status['Questions'] * 100);
     echo '</td></tr>';
     if (function_exists('apc_cache_info')) {
         $_apc_cache_info = apc_cache_info();
         echo '<tr><td colspan="2" align="left"><div class="notify">';
         _v_ico_silk('database_lightning');
         echo ' 高速缓存子系统 Alternative PHP Cache ' . _vo_ico_silk('tick') . ' <strong>ACTIVE</strong></div></td></tr>';
         echo '<tr><td colspan="2" align="left"><span class="tip">性能数据</span></td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">命中次数</td><td class="section_even" align="left">' . $_apc_cache_info['num_hits'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_odd">错失次数</td><td class="section_odd" align="left">' . $_apc_cache_info['num_misses'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">储存的条目数量</td><td class="section_even" align="left">' . $_apc_cache_info['num_entries'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_odd">插入次数</td><td class="section_odd" align="left">' . $_apc_cache_info['num_inserts'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">缓存中的文件尺寸</td><td class="section_even" align="left">' . intval($_apc_cache_info['mem_size'] / 1024) . 'KB</td></tr>';
     } else {
         echo '<tr><td colspan="2" align="left"><div class="notify">';
         _v_ico_silk('database_lightning');
         echo ' 高速缓存子系统 Alternative PHP Cache ' . _vo_ico_silk('exclamation') . ' <strong><small>N/A</small></strong>';
         echo '</div></td></tr>';
     }
     if (ZEND_CACHE_MEMCACHED_ENABLED == 'yes') {
         $mem = new Memcache();
         $mem->addServer(ZEND_CACHE_OPTIONS_MEMCACHED_SERVER, ZEND_CACHE_OPTIONS_MEMCACHED_PORT);
         $_memcached_stats = $mem->getExtendedStats();
         $_mstats = $_memcached_stats[ZEND_CACHE_OPTIONS_MEMCACHED_SERVER . ':' . ZEND_CACHE_OPTIONS_MEMCACHED_PORT];
         echo '<tr><td colspan="2" align="left"><div class="notify">';
         _v_ico_silk('database_lightning');
         echo ' 高速缓存子系统 Memcached ' . _vo_ico_silk('tick') . ' <strong>ACTIVE</strong>';
         echo '</div></td></tr>';
         echo '<tr><td colspan="2" align="left"><span class="tip">数据库系统信息</span></td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">版本</td><td class="section_even" align="left">' . $_mstats['version'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_odd">运转时间</td><td class="section_odd" align="left">' . $_mstats['uptime'] . ' 秒</td></tr>';
         echo '<tr><td colspan="2" align="left"><span class="tip">性能数据</span></td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">命中次数</td><td class="section_even" align="left">' . $_mstats['get_hits'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_odd">错失次数</td><td class="section_odd" align="left">' . $_mstats['get_misses'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">储存的条目数量</td><td class="section_even" align="left">' . $_mstats['curr_items'] . '</td></tr>';
         echo '<tr><td width="150" align="right" class="section_odd">读取字节数</td><td class="section_odd" align="left">' . intval($_mstats['bytes_read'] / 1024) . 'KB</td></tr>';
         echo '<tr><td width="150" align="right" class="section_even">写入字节数</td><td class="section_even" align="left">' . intval($_mstats['bytes_written'] / 1024) . 'KB</td></tr>';
         echo '<tr><td width="150" align="right" class="section_odd">总连接数</td><td class="section_odd" align="left">' . $_mstats['total_connections'] . '</td></tr>';
     } else {
         echo '<tr><td colspan="2" align="left"><div class="notify">';
         _v_ico_silk('database_lightning');
         echo ' 高速缓存子系统 Memcached ' . _vo_ico_silk('exclamation') . ' <strong><small>N/A</small></strong>';
         echo '</div></td></tr>';
     }
     echo '</table>';
     echo '</div>';
     echo '</div>';
 }
Exemple #23
0
 /**
  * Get the statistics output from the current memcache pool.
  *
  * @return array  The output from Memcache::getExtendedStats() using the
  *                current configuration values.
  */
 public function stats()
 {
     return $this->_memcache->getExtendedStats();
 }
Exemple #24
0
<?php

/**
 * Memcached monitor service
 * returns JSON to be consumed by the client javascript
 * 
 * @author Jason Hinkle http://www.verysimple.com
 * @version 1.0
 */
require_once "_config.php";
require_once "verysimple/HTTP/Request.php";
require_once "JSON.php";
$id = Request::Get("id", 0);
$info = $servers[$id];
$memcache = new Memcache();
$memcache->addServer($info->host, $info->port);
$stats = @$memcache->getExtendedStats();
$json = new Services_JSON();
header("Content-Type: application/json");
print $json->encode($stats[$info->getKey()]);
Exemple #25
0
 public function getStatus()
 {
     return $this->instance->getExtendedStats();
 }
Exemple #26
0
// +----------------------------------------------------------------------
// | Fileanme: memcache.php
// +----------------------------------------------------------------------
// | Description: CoolTools
// +----------------------------------------------------------------------
// | Author: aboc <*****@*****.**>
// +----------------------------------------------------------------------
// | Date: 2014-5-15 16:16:49
// +----------------------------------------------------------------------
if (isset($_POST['find'])) {
    $host = $_POST['host'];
    $port = $_POST['port'];
    $mem = new Memcache();
    $mem->connect($host, $port);
    $items = $mem->getExtendedStats('items');
    print_r($items);
    $items = $items["{$host}:{$port}"]['items'];
    if (!is_array($items)) {
        $items = array();
    }
    foreach ($items as $key => $values) {
        $number = $key;
        $str = $mem->getExtendedStats("cachedump", $number, 0);
        $line = $str["{$host}:{$port}"];
        if (is_array($line) && count($line) > 0) {
            $item = $_POST['item'];
            $length = strlen($item);
            foreach ($line as $key => $value) {
                if ($length > 0) {
                    if (substr($key, 0, $length) != $item) {
 /**
  * {@inheritdoc}
  */
 public function stats()
 {
     return $this->memc->getExtendedStats();
 }
 private function get_data($max_entries = 500, $host, $port = '11211')
 {
     $mem = new \Memcache();
     $mem->connect($host, $port);
     $list = array();
     $allSlabs = $mem->getExtendedStats('slabs');
     $items = $mem->getExtendedStats('items');
     $data = array();
     foreach ($allSlabs as $server => $slabs) {
         foreach ($slabs as $slabId => $slabMeta) {
             $cdump = $mem->getExtendedStats('cachedump', (int) $slabId, $max_entries);
             foreach ($cdump as $server => $entries) {
                 if ($entries) {
                     foreach ($entries as $eName => $eData) {
                         $the_key = esc_attr($eName);
                         $the_value = esc_attr($mem->get($the_key));
                         $data[$the_key] = $the_value;
                     }
                 }
             }
         }
     }
     return $data;
 }
Exemple #29
0
 /**
  * Get the statistics output from the current memcache pool.
  *
  * @return array  The output from Memcache::getExtendedStats() using the
  *                current configuration values.
  */
 public function stats()
 {
     return $this->_memcache instanceof Memcached ? $this->_memcache->getStats() : $this->_memcache->getExtendedStats();
 }
Exemple #30
0
 public function post($interval = 600)
 {
     $memcache = new Memcache();
     $memcache->connect('localhost', 11211) or die("Could not connect");
     echo "memcache activated\n";
     echo "collect past = {$interval} seconds\n";
     $time = new Datetime();
     $time->sub(new DateInterval('PT' . $interval . 'S'));
     echo 'time=' . $time->format('Y-m-d H:i:s');
     echo "\n";
     echo 'time=' . $time->getTimestamp();
     echo "\n";
     $key_pattern = "/\\A\\d\\d\\d\\d-\\d+.\\d+\\z/";
     $posts = array();
     $lists_key = array();
     $allSlabs = $memcache->getExtendedStats('slabs');
     foreach ($allSlabs as $server => $slabs) {
         foreach ($slabs as $slabId => $slabMeta) {
             if (!is_numeric($slabId)) {
                 continue;
             }
             $cdump = $memcache->getExtendedStats('cachedump', (int) $slabId, 0);
             //echo count($cdump);
             foreach ($cdump as $keys => $arrVal) {
                 if (!is_array($arrVal)) {
                     continue;
                 }
                 //echo count($arrVal);
                 foreach ($arrVal as $k => $v) {
                     //						echo $k .' - '.date('H:i d.m.Y',$v[1]).' , ';
                     $res = preg_match($key_pattern, $k);
                     if (!$res) {
                         continue;
                     }
                     $obj = $memcache->get($k);
                     if (!$obj) {
                         continue;
                     }
                     echo $k . ' : ';
                     $key_time = substr($k, 5);
                     if ((double) $key_time >= (double) $time->getTimestamp()) {
                         echo "not yet\n";
                         continue;
                     }
                     $lists_key[] = $k;
                     $posts[] = (array) $obj;
                     echo 'collect : ';
                     echo "\n";
                 }
             }
         }
     }
     echo count($posts) . ' collected';
     echo "\n";
     if (count($posts)) {
         echo "batch insert : ";
         $res = $this->db->insert_batch('post', $posts);
     }
     if (!$res) {
         echo " FAILED\n";
     } else {
         echo " SECCESS\n";
         echo "Delete Key im memcache : ";
         foreach ($lists_key as $lk) {
             $memcache->delete($lk) or die("Could not delete : {$k}\n");
         }
         echo "SUCCESS\n";
     }
     $memcache->close();
     echo "memcache closed\n";
 }