<?php
/*
+----------------------------------------------------------------------+
| PHP バージョン 5 |
+----------------------------------------------------------------------+
| 著作権 (c) 1997-2004 PHP グループ |
+----------------------------------------------------------------------+
| このソースファイルは PHP ライセンスのバージョン 3.0 の対象となります。|
| このパッケージに LICENSE ファイルでバンドルされており、|
| 次の URL からワールド ワイド ウェブ経由で入手できます: |
| http://www.php.net/license/3_0.txt. |
| PHP ライセンスのコピーを受け取っておらず、 |
| ワールドワイドウェブから入手する場合は、次の宛先にメモを送信してください |
| [email protected] までご連絡いただければ、すぐにコピーをお送りいたします。 |
+----------------------------------------------------------------------+
| 著者: Harun Yayli <harunyayli at gmail.com> |
+----------------------------------------------------------------------+
*/
//memcached グラフィカル ガジェット $VERSION='$Id: memcache.php,v 1.1.2.3 2008/08/28 18:07:54 mikl Exp $';
#ユーザー名を設定する define('ADMIN_USERNAME','admin');
#パスワードを設定する define('ADMIN_PASSWORD','123456');
定義('DATE_FORMAT','Y/m/d H:i:s');
定義('GRAPH_SIZE',200);
定義('MAX_ITEM_DUMP',50);
#memcachedホスト情報を設定します $MEMCACHE_SERVERS[] = '192.168.29.133:11211';
////////// デフォルト設定領域の終了 //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
$_SERVER['PHP_AUTH_USER'] が設定されている場合 || $_SERVER['PHP_AUTH_PW'] が設定されている場合 ||
$_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME || $_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD) {
ヘッダー("WWW-Authenticate: 基本レルム=\"Memcache ログイン\"");
ヘッダー("HTTP/1.0 401 権限がありません");
エコー <<<EOB
<html><本文>
<h1>拒否されました!</h1>
<big>ユーザー名またはパスワードが間違っています!</big>
</body></html>
EOB;
出口;
}
/////////////MEMCACHE 関数 /////////////////////////////////////////////////////////////////////////
関数sendMemcacheCommands($command){
グローバル $MEMCACHE_SERVERS;
$結果 = 配列();
foreach($MEMCACHE_SERVERS を $server として){
$strs = 爆発します(':',$server);
$host = $strs[0];
$port = $strs[1];
$result[$server] = sendMemcacheCommand($host,$port,$command);
}
$result を返します。
}
関数sendMemcacheCommand($server,$port,$command){
$s = @fsockopen($server,$port);
もし (!$s){
die("接続できません:".$server.':'.$port);
}
fwrite($s, $command."\r\n");
$buf='';
((!feof($s))) の間 {
$buf .= fgets($s, 256);
if (strpos($buf,"END\r\n")!==false){ // 統計は終了を示す
壊す;
}
if (strpos($buf,"DELETED\r\n")!==false || strpos($buf,"NOT_FOUND\r\n")!==false){ // delete は次のように言います
壊す;
}
if (strpos($buf,"OK\r\n")!==false){ // flush_all は OK と表示
壊す;
}
}
fclose($s);
parseMemcacheResults($buf) を返します。
}
関数parseMemcacheResults($str){
$res = 配列();
$lines = 爆発("\r\n",$str);
$cnt = count($lines);
($i=0; $i< $cnt; $i++){
$line = $lines[$i];
$l = 爆発します(' ',$line,3);
(count($l)==3)の場合{
$res[$l[0]][$l[1]]=$l[2];
if ($l[0]=='VALUE'){ // 次の行は値です
$res[$l[0]][$l[1]] = 配列();
リスト ($flag,$size) = 爆発(' ',$l[2]);
$res[$l[0]][$l[1]]['stat']=配列('flag'=>$flag,'size'=>$size);
$res[$l[0]][$l[1]]['値']=$lines[++$i];
}
}elseif($line=='削除済み' || $line=='見つかりません' || $line=='OK'){
$line を返します。
}
}
$res を返します。
}
関数 dumpCacheSlab($server,$slabId,$limit){
リスト($host、$port) = 爆発(':'、$server);
$resp = sendMemcacheCommand($host、$port、'stats cachedump '.$slabId.' '.$limit);
$resp を返します。
}
関数flushServer($server){
リスト($host、$port) = 爆発(':'、$server);
$resp = sendMemcacheCommand($host、$port、'flush_all');
$resp を返します。
}
関数 getCacheItems(){
$items = sendMemcacheCommands('統計アイテム');
$serverItems = 配列();
$totalItems = 配列();
foreach ($items を $server=>$itemlist として){
$serverItems[$server] = 配列();
$totalItems[$server] = 0;
if (!isset($itemlist['STAT'])){
続く;
}
$iteminfo = $itemlist['STAT'];
foreach($iteminfo を $keyinfo=>$value として){
if (preg_match('/items\:(\d+?)\:(.+?)$/',$keyinfo,$matches)){
$serverItems[$server][$matches[1]][$matches[2]] = $value;
($matches[2]=='数値')の場合{
$totalItems[$server] +=$value;
}
}
}
}
配列を返します('items'=>$serverItems,'counts'=>$totalItems);
}
関数 getMemcacheStats($total=true){
$resp = sendMemcacheCommands('統計');
($合計){
$res = 配列();
foreach($resp を $server=>$r として){
foreach($r['STAT'] を $key=>$row として){
if (!isset($res[$key])){
$res[$key] = null;
}
スイッチ ($key){
ケース 'pid':
$res['pid'][$server]=$row;
壊す;
ケース「稼働時間」:
$res['uptime'][$server]=$row;
壊す;
ケース '時間':
$res['time'][$server]=$row;
壊す;
ケース 'バージョン':
$res['version'][$server]=$row;
壊す;
ケース 'pointer_size':
$res['pointer_size'][$server]=$row;
壊す;
'rusage_user'の場合:
$res['rusage_user'][$server]=$row;
壊す;
ケース 'rusage_system':
$res['rusage_system'][$server]=$row;
壊す;
ケース 'curr_items':
$res['curr_items']+=$row;
壊す;
ケース 'total_items':
$res['total_items']+=$row;
壊す;
ケース 'バイト':
$res['バイト']+=$row;
壊す;
ケース 'curr_connections':
$res['curr_connections']+=$row;
壊す;
ケース 'total_connections':
$res['total_connections']+=$row;
壊す;
ケース 'connection_structures':
$res['connection_structures']+=$row;
壊す;
ケース 'cmd_get':
$res['cmd_get']+=$row;
壊す;
ケース 'cmd_set':
$res['cmd_set']+=$row;
壊す;
ケース 'get_hits':
$res['get_hits']+=$row;
壊す;
ケース 'get_misses':
$res['get_misses']+=$row;
壊す;
ケース「立ち退き」:
$res['立ち退き']+=$row;
壊す;
ケース 'bytes_read':
$res['bytes_read']+=$row;
壊す;
ケース 'bytes_written':
$res['bytes_written']+=$row;
壊す;
'limit_maxbytes'の場合:
$res['limit_maxbytes']+=$row;
壊す;
ケース「スレッド」:
$res['rusage_system'][$server]=$row;
壊す;
}
}
}
$res を返します。
}
$resp を返します。
}
//////////////////////////////////////////////////////
//
// このページをキャッシュしない
//
ヘッダー("Cache-Control: no-store、no-cache、must-revalidate"); // HTTP/1.1
ヘッダー("Cache-Control: post-check=0, pre-check=0", false);
ヘッダー("プラグマ: キャッシュなし"); // HTTP/1.0
関数の持続時間($ts) {
グローバル $time;
$years = (int)((($time - $ts)/(7*86400))/52.177457);
$rem = (int)(($time - $ts) - ($years * 52.177457 * 7 * 86400));
$weeks = (int)(($rem)/(7*86400));
$days = (int)(($rem)/86400) - $weeks*7;
$hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
$mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
$str = '';
if($years==1) $str .= "$years 年, ";
if($years>1) $str .= "$years 年, ";
if($weeks==1) $str .= "$weeks 週、";
if($weeks>1) $str .= "$weeks 週間、";
if($days==1) $str .= "$days 日,";
if($days>1) $str .= "$days 日,";
if($hours == 1) $str .= "$hours 時間と";
if($hours>1) $str .= " $hours 時間と";
if($mins == 1) $str .= " 1分";
そうでない場合、$str .= "$mins 分";
$str を返します。
}
// グラフィックを作成する
//
関数 graphics_avail() {
extension_loaded('gd') を返します。
}
関数 bsize($s) {
foreach (配列('','K','M','G') を $i => $k として) {
($s < 1024) の場合、break;
$s/=1024;
}
sprintf("%5.1f %sBytes",$s,$k) を返します。
}
// メニューエントリを作成する
関数 menu_entry($ob,$title) {
グローバル $PHP_SELF;
($ob == $_GET['op'])の場合{
"<li><a class=\"child_active\" href=\"$PHP_SELF&op=$ob\">$title</a></li>" を返します。
}
"<li><a class=\"active\" href=\"$PHP_SELF&op=$ob\">$title</a></li>" を返します。
}
関数 getHeader(){
$ヘッダー = <<<EOB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>MEMCACHE 情報</title>
<スタイル タイプ="text/css"><!--
本文 { 背景:白; フォントサイズ:100.01%; 余白:0; パディング:0; }
本文、p、td、th、入力、送信 { フォントサイズ:0.8em; フォントファミリー:arial、helvetica、sans-serif; }
* html 本文 {font-size:0.8em}
* html p {フォントサイズ:0.8em}
* html td {フォントサイズ:0.8em}
* html th {フォントサイズ:0.8em}
* html 入力 {font-size:0.8em}
* html 送信 {font-size:0.8em}
td { 垂直方向の配置: 上 }
a { 色:黒; フォントの太さ:なし; テキストの装飾:なし; }
a:hover { テキスト装飾:下線; }
div.content { パディング:1em 1em 1em 1em; 位置:絶対; 幅:97%; z-index:100; }
h1.memcache { 背景:rgb(153,153,204); マージン:0; パディング:0.5em 1em 0.5em 1em; }
* html h1.memcache { margin-bottom:-7px; }
h1.memcache a:hover { テキスト装飾:なし; 色:rgb(90,90,90); }
h1.memcache span.logo {
背景:rgb(119,123,180);
色:黒;
右境界線: 黒一色 1px;
border-bottom: 黒一色 1px;
フォントスタイル:斜体;
フォントサイズ:1em;
パディング左:1.2em;
右パディング:1.2em;
テキスト配置:右;
表示:ブロック;
幅:130ピクセル;
}
h1.memcache span.logo span.name { color:white; font-size:0.7em; padding:0 0.8em 0 2em; }
h1.memcache span.nameinfo { 色:白; 表示:インライン; フォントサイズ:0.4em; 左余白: 3em; }
h1.memcache div.copy { 色:黒; フォントサイズ:0.4em; 位置:絶対; 右:1em; }
hr.memcache {
背景:白;
ボーダー下部:solid rgb(102,102,153) 1px;
境界線スタイル:なし;
上ボーダー:solid rgb(102,102,153) 10px;
高さ:12px;
マージン:0;
上マージン:1px;
パディング:0;
}
ol、メニュー { マージン:1em 0 0 0; パディング:0.2em; 左マージン:1em;}
ol.menu li { 表示:インライン; 右マージン:0.7em; リストスタイル:なし; フォントサイズ:85%}
ol.menu {
背景:rgb(153,153,204);
境界線:実線 rgb(102,102,153) 2px;
色:白;
フォントの太さ:太字;
右マージン:0em;
パディング:0.1em 0.5em 0.1em 0.5em;
テキスト装飾:なし;
左マージン: 5px;
}
ol.menu a.child_active {
背景:rgb(153,153,204);
境界線:実線 rgb(102,102,153) 2px;
色:白;
フォントの太さ:太字;
右マージン:0em;
パディング:0.1em 0.5em 0.1em 0.5em;
テキスト装飾:なし;
左境界線: 黒一色 5px;
左マージン: 0px;
}
ol.menu span.active {
背景:rgb(153,153,204);
境界線:実線 rgb(102,102,153) 2px;
色:黒;
フォントの太さ:太字;
右マージン:0em;
パディング:0.1em 0.5em 0.1em 0.5em;
テキスト装飾:なし;
左境界線: 黒一色 5px;
}
ol.menu span.inactive {
背景:rgb(193,193,244);
境界線:実線 rgb(182,182,233) 2px;
色:白;
フォントの太さ:太字;
右マージン:0em;
パディング:0.1em 0.5em 0.1em 0.5em;
テキスト装飾:なし;
左マージン: 5px;
}
ol.menu a:hover {
背景:rgb(193,193,244);
テキスト装飾:なし;
}
div.info {
背景:rgb(204,204,204);
境界線:実線 rgb(204,204,204) 1px;
マージン下部:1em;
}
div.info h2 {
背景:rgb(204,204,204);
色:黒;
フォントサイズ:1em;
マージン:0;
パディング:0.1em 1em 0.1em 1em;
}
div.info テーブル {
境界線:実線 rgb(204,204,204) 1px;
境界線の間隔:0;
幅:100%;
}
div.info テーブル th {
背景:rgb(204,204,204);
色:白;
マージン:0;
パディング:0.1em 1em 0.1em 1em;
}
div.info テーブル th a.sortable { color:black; }
div.info テーブル tr.tr-0 { background:rgb(238,238,238); }
div.info テーブル tr.tr-1 { background:rgb(221,221,221); }
div.info テーブル td { パディング:0.3em 1em 0.3em 1em; }
div.info テーブル td.td-0 { border-right:solid rgb(102,102,153) 1px; white-space:nowrap; }
div.info テーブル td.td-n { border-right:solid rgb(102,102,153) 1px; }
div.info テーブル td h3 {
色:黒;
フォントサイズ:1.1em;
左マージン:-0.3em;
}
.td-0 a 、.td-n a、.tr-0 a 、tr-1 a {
テキスト装飾:下線;
}
div.graph { マージン下部:1em }
div.graph h2 { 背景:rgb(204,204,204);; 色:黒; フォントサイズ:1em; 余白:0; パディング:0.1em 1em 0.1em 1em; }
div.graph テーブル { border:solid rgb(204,204,204) 1px; color:black; font-weight:normal; width:100%; }
div.graph テーブル td.td-0 { 背景:rgb(238,238,238); }
div.graph テーブル td.td-1 { 背景:rgb(221,221,221); }
div.graph テーブル td { パディング:0.2em 1em 0.4em 1em; }
div.div1、div.div2 { マージン下部:1em; 幅:35em; }
div.div3 { 位置:絶対; 左:40em; 上:1em; 幅:580px; }
//div.div3 { 位置:絶対; 左:37em; 上:1em; 右:1em; }
div.sorting { マージン:1.5em 0em 1.5em 2em }
.center { テキスト配置:center }
.aright { 位置:絶対;右:1em }
.right { テキスト配置:right }
.ok { 色:rgb(0,200,0); フォントの太さ:太字}
.failed { color:rgb(200,0,0); font-weight:bold}
span.box {
境界線: 黒実線 1px;
右境界線:黒実線 2px;
border-bottom:黒一色 2px;
パディング:0 0.5em 0 0.5em;
右マージン:1em;
}
span.green { 背景:#60F060; パディング:0 0.5em 0 0.5em}
span.red { 背景:#D06030; パディング:0 0.5em 0 0.5em }
div.認証が必要{
背景:rgb(238,238,238);
境界線:実線 rgb(204,204,204) 1px;
色:rgb(200,0,0);
フォントサイズ:1.2em;
フォントの太さ:太字;
パディング:2em;
テキスト配置:中央;
}
入力{
背景:rgb(153,153,204);
境界線:実線 rgb(102,102,153) 2px;
色:白;
フォントの太さ:太字;
右マージン:1em;
パディング:0.1em 0.5em 0.1em 0.5em;
}
//-->
</スタイル>
</head>
<本文>
<div class="head">
<h1 class="memcache">
<span class="logo"><a href="http://pecl.php.net/package/memcache" rel="external nofollow" >memcache</a></span>
Harun Yayli による memcache.php
</h1>
<hr class="memcache">
</div>
<div クラス = コンテンツ>
EOB;
$headerを返します。
}
関数 getFooter(){
グローバル $VERSION;
$footer = '</div><!-- apc.php '.$VERSION.' に基づいています--></body>
</html>
';
$footer を返します。
}
関数 getMenu(){
グローバル $PHP_SELF;
echo "<ol class=menu>";
($_GET['op']!=4)の場合{
エコー <<<EOB
<li><a href="$PHP_SELF&op={$_GET['op']}" rel="external nofollow" >データの更新</a></li>
EOB;
}
それ以外 {
エコー <<<EOB
<li><a href="$PHP_SELF&op=2}" rel="external nofollow" >戻る</a></li>
EOB;
}
エコー
menu_entry(1,'ホスト統計情報を表示'),
menu_entry(2,'変数');
エコー <<<EOB
</ol>
<br/>
EOB;
}
// TODO、認証
$_GET['op'] = !isset($_GET['op'])? '1':$_GET['op'];
$PHP_SELF = isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],'')) : '';
$PHP_SELF=$PHP_SELF.'?';
時間
// _GET をサニタイズする
foreach($_GET を $key=>$g として){
$_GET[$key] = htmlentities($g);
}
// シングルアウト
// singleout が設定されている場合は、そのサーバーの詳細のみが提供されます。
if (isset($_GET['singleout']) && $_GET['singleout']>=0 && $_GET['singleout'] <count($MEMCACHE_SERVERS)){
$MEMCACHE_SERVERS = 配列($MEMCACHE_SERVERS[$_GET['singleout']]);
}
// 画像を表示
(isset($_GET['IMG']))の場合{
$memcacheStats = getMemcacheStats();
$memcacheStatsSingle = getMemcacheStats(false);
グラフィックスが利用可能であれば
終了(0);
}
関数 fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='') {
グローバル $col_black;
$x1=$x+$w-1;
$y1=$y+$h-1;
画像の長方形($im, $x, $y1, $x1+1, $y+1, $col_black);
$y1>$y の場合、画像で満たされた長方形 ($im、$x、$y、$x1、$y1、$color2)。
そうでない場合は、imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
画像の長方形($im, $x, $y1, $x1, $y, $color1);
($text) の場合 {
($placeindex>0)の場合{
($placeindex<16)の場合
{
$px = 5;
$py=$placeindex*12+6;
画像で塗りつぶされた長方形($im, $px+90, $py+3, $px+90-4, $py-3, $color2);
イメージライン($im,$x,$y+$h/2,$px+90,$py,$color2);
画像文字列($im,2,$px,$py-6,$text,$color1);
} それ以外 {
($placeindex<31)の場合{
$px=$x+40*2;
$py=($placeindex-15)*12+6;
} それ以外 {
$px=$x+40*2+100*intval(($placeindex-15)/15);
$py=($placeindex%15)*12+6;
}
画像で塗りつぶされた長方形($im、$px、$py+3、$px-4、$py-3、$color2);
イメージライン($im,$x+$w,$y+$h/2,$px,$py,$color2);
画像文字列($im,2,$px+2,$py-6,$text,$color1);
}
} それ以外 {
画像文字列($im,4,$x+5,$y1-16,$text,$color1);
}
}
}
関数 fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $color2, $text='', $placeindex=0) {
$r=$直径/2;
$w=deg2rad((360+$start+($end-$start)/2)%360);
if (function_exists("imagefilledarc")) {
// GD 2.0.1 が利用可能な場合にのみ存在します
画像を埋め込んだアーク($im、$centerX+1、$centerY+1、$diameter、$diameter、$start、$end、$color1、IMG_ARC_PIE);
画像を埋め込んだアーク($im、$centerX、$centerY、$diameter、$diameter、$start、$end、$color2、IMG_ARC_PIE);
画像が塗りつぶされたアーク($im、$centerX、$centerY、$diameter、$diameter、$start、$end、$color1、IMG_ARC_NOFILL|IMG_ARC_EDGED);
} それ以外 {
イメージアーク($im、$centerX、$centerY、$diameter、$diameter、$start、$end、$color2);
イメージライン($im、$centerX、$centerY、$centerX + cos(deg2rad($start)) * $r、$centerY + sin(deg2rad($start)) * $r、$color2);
イメージライン($im、$centerX、$centerY、$centerX + cos(deg2rad($start+1)) * $r、$centerY + sin(deg2rad($start)) * $r、$color2);
イメージライン($im、$centerX、$centerY、$centerX + cos(deg2rad($end-1)) * $r、$centerY + sin(deg2rad($end)) * $r、$color2);
イメージライン($im、$centerX、$centerY、$centerX + cos(deg2rad($end)) * $r、$centerY + sin(deg2rad($end)) * $r、$color2);
イメージフィル($im、$centerX + $r*cos($w)/2、$centerY + $r*sin($w)/2、$color2);
}
($text) の場合 {
($placeindex>0)の場合{
イメージライン($im、$centerX + $r*cos($w)/2、$centerY + $r*sin($w)/2、$直径、$placeindex*12、$color1);
画像文字列($im,4,$直径, $placeindex*12,$テキスト,$色1);
} それ以外 {
イメージ文字列($im、4、$centerX + $r*cos($w)/2、$centerY + $r*sin($w)/2、$text、$color1);
}
}
}
$size = GRAPH_SIZE; // 画像サイズ
$image = imagecreate($size+50, $size+10);
$col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$col_red = imagecolorallocate($image, 0xD0, 0x60, 0x30);
$col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
$col_black = imagecolorallocate($image, 0, 0, 0);
イメージカラーを透明にします($image,$col_white);
スイッチ ($_GET['IMG']){
ケース 1: // 円グラフ
$tsize=$memcacheStats['limit_maxbytes'];
$avail=$tsize-$memcacheStats['bytes'];
$x = $y = $サイズ/2;
$角度_from = 0;
$ファズ = 0.000001;
foreach($memcacheStatsSingle を $serv=>$mcs として) {
$free = $mcs['STAT']['limit_maxbytes']-$mcs['STAT']['bytes'];
$used = $mcs['STAT']['バイト'];
($free>0)の場合{
// 無料で描画
$angle_to = ($free*360)/$tsize;
$perc =sprintf("%.2f%%", ($free *100) / $tsize);
fill_arc($image,$x,$y,$size,$angle_from,$angle_from + $angle_to,$col_black,$col_green,$perc);
$angle_from = $angle_from + $angle_to;
}
($used>0)の場合{
// 描画使用
$angle_to = ($used*360)/$tsize;
$perc =sprintf("%.2f%%", ($used *100) / $tsize);
fill_arc($image,$x,$y,$size,$angle_from,$angle_from + $angle_to,$col_black,$col_red, '('.$perc.')' );
$angle_from = $angle_from + $angle_to;
}
}
壊す;
ケース 2: // ヒット ミス
$hits = ($memcacheStats['get_hits']==0) ? 1:$memcacheStats['get_hits'];
$misses = ($memcacheStats['get_misses']==0) ? 1:$memcacheStats['get_misses'];
$total = $hits + $misses ;
fill_box($image, 30,$size,50,-$hits*($size-21)/$total,$col_black,$col_green,sprintf("%.1f%%",$hits*100/$total));
fill_box($image,130,$size,50,-max(4,($total-$hits)*($size-21)/$total),$col_black,$col_red,sprintf("%.1f%%",$misses*100/$total));
壊す;
}
ヘッダー("コンテンツタイプ: image/png");
画像png($image);
出口;
}
エコー getHeader();
getMenu() をエコーします。
スイッチ ($_GET['op']) {
ケース 1: // ホスト統計
phpversion のバージョン番号
$memcacheStats = getMemcacheStats();
$memcacheStatsSingle = getMemcacheStats(false);
$mem_size = $memcacheStats['limit_maxbytes'];
$mem_used = $memcacheStats['バイト'];
$mem_avail = $mem_size - $mem_used;
$startTime = time()-array_sum($memcacheStats['uptime']);
$curr_items = $memcacheStats['curr_items'];
$total_items = $memcacheStats['total_items'];
$hits = ($memcacheStats['get_hits']==0) ? 1:$memcacheStats['get_hits'];
$misses = ($memcacheStats['get_misses']==0) ? 1:$memcacheStats['get_misses'];
$sets = $memcacheStats['cmd_set'];
$req_rate = sprintf("%.2f",($hits+$misses)/($time-$startTime));
$hit_rate = sprintf("%.2f",($hits)/($time-$startTime));
$miss_rate = sprintf("%.2f",($misses)/($time-$startTime));
$set_rate = sprintf("%.2f",($sets)/($time-$startTime));
エコー <<< EOB
<div class="info div1"><h2>一般的なキャッシュ情報</h2>
<テーブルセル間隔=0><tbody>
<tr class=tr-1><td class=td-0>PHP バージョン</td><td>$phpversion</td></tr>
EOB;
echo "<tr class=tr-0><td class=td-0>Memcached ホスト。((count($MEMCACHE_SERVERS)>1) ? 's':'')."</td><td>";
$i = 0;
if (!isset($_GET['singleout']) && count($MEMCACHE_SERVERS)>1){
foreach($MEMCACHE_SERVERS を $server として){
echo ($i+1).'. <a href="'.$PHP_SELF.'&singleout='.$i++.'" rel="external nofollow" >'.$server.'</a><br/>';
}
}
それ以外{
'1.'.$MEMCACHE_SERVERS[0]をエコーします。
}
if (isset($_GET['singleout'])){
echo '<a href="'.$PHP_SELF.'" rel="external nofollow" >(すべてのサーバー)</a><br/>';
}
echo "</td></tr>\n";
echo "<tr class=tr-1><td class=td-0>Memcache キャッシュの合計</td><td>".bsize($memcacheStats['limit_maxbytes']).</td></tr>\n";
エコー <<<EOB
</tbody></table>
</div>
<div class="info div1"><h2>Memcache サーバー情報</h2>
EOB;
foreach($MEMCACHE_SERVERS を $server として){
echo '<テーブルセル間隔=0><tbody>';
echo '<tr class=tr-1><td class=td-1>'.$server.'</td><td><a href="'.$PHP_SELF.'&server='.array_search($server,$MEMCACHE_SERVERS).'&op=6" rel="external nofollow" >[<b>このサーバーをフラッシュする</b>]</a></td></tr>';
echo '<tr class=tr-0><td class=td-0>開始時刻</td><td>',date(DATE_FORMAT,$memcacheStatsSingle[$server]['STAT']['time']-$memcacheStatsSingle[$server]['STAT']['uptime']),'</td></tr>';
echo '<tr class=tr-1><td class=td-0>稼働時間</td><td>',duration($memcacheStatsSingle[$server]['STAT']['time']-$memcacheStatsSingle[$server]['STAT']['uptime']),'</td></tr>';
echo '<tr class=tr-0><td class=td-0>Memcached サーバーのバージョン</td><td>'.$memcacheStatsSingle[$server]['STAT']['version'].'</td></tr>';
echo '<tr class=tr-1><td class=td-0>使用済みキャッシュサイズ</td><td>',bsize($memcacheStatsSingle[$server]['STAT']['bytes']),'</td></tr>';
echo '<tr class=tr-0><td class=td-0>合計キャッシュサイズ</td><td>',bsize($memcacheStatsSingle[$server]['STAT']['limit_maxbytes']),'</td></tr>';
エコー '</tbody></table>';
}
エコー <<<EOB
</div>
<div class="graph div3"><h2>ホスト ステータス図</h2>
<テーブルセル間隔=0><tbody>
EOB;
$size='幅='.(GRAPH_SIZE+50).' 高さ='.(GRAPH_SIZE+10);
エコー <<<EOB
<tr>
<td class=td-0>キャッシュの使用</td>
<td class=td-1>ヒットとミス</td>
</tr>
EOB;
エコー
graphics_avail() ?
'<tr>' です。
"<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF&IMG=1&".(isset($_GET['singleout'])? 'singleout='.$_GET['singleout'].'&':'').."$time\"></td>"。
"<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF&IMG=2&".(isset($_GET['singleout'])? 'singleout='.$_GET['singleout'].'&':'')."$time\"></td></tr>\n"
: "",
'<tr>',
'<td class=td-0><span class="green box"> </span>空き容量: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
'<td class=td-1><span class="green box"> </span>ヒット数: ',$hits.sprintf(" (%.1f%%)",$hits*100/($hits+$misses)),"</td>\n",
'</tr>',
'<tr>',
'<td class=td-0><span class="red box"> </span>使用済み: ',bsize($mem_used ).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
'<td class=td-1><span class="red box"> </span>ミス: ',$misses.sprintf(" (%.1f%%)",$misses*100/($hits+$misses)),"</td>\n";
エコー <<< EOB
</tr>
</tbody></table>
<br/>
<div class="info"><h2>キャッシュ情報</h2>
<テーブルセル間隔=0><tbody>
<tr class=tr-0><td class=td-0>現在のアイテム(合計)</td><td>$curr_items ($total_items)</td></tr>
<tr class=tr-1><td class=td-0>ヒット数</td><td>{$hits}</td></tr>
<tr class=tr-0><td class=td-0>ミス</td><td>{$misses}</td></tr>
<tr class=tr-1><td class=td-0>リクエスト レート (ヒット、ミス)</td><td>$req_rate キャッシュ リクエスト数/秒</td></tr>
<tr class=tr-0><td class=td-0>ヒット率</td><td>$hit_rate キャッシュリクエスト数/秒</td></tr>
<tr class=tr-1><td class=td-0>ミス率</td><td>$miss_rate キャッシュリクエスト数/秒</td></tr>
<tr class=tr-0><td class=td-0>レートの設定</td><td>$set_rate キャッシュリクエスト数/秒</td></tr>
</tbody></table>
</div>
EOB;
壊す;
ケース 2: // 変数
m = 0;
キャッシュアイテムを取得します。
$items = $cacheItems['items'];
$totals = $cacheItems['counts'];
ダンプのサイズは MAX_ITEM_DUMP です。
foreach($items を $server => $entries として) {
エコー <<< EOB
<div class="info"><テーブルセル間隔=0><tbody>
<tr><th colspan="2">$サーバー</th></tr>
<tr><th>スラブ ID</th><th>情報</th></tr>
EOB;
foreach($entries を $slabId => $slab として) {
$dumpUrl = $PHP_SELF.'&op=2&server='.(array_search($server,$MEMCACHE_SERVERS)).'&dumpslab='.$slabId;
エコー
"<tr class=tr-$m>",
"<td class=td-0><center>",'<a href="',$dumpUrl,'" rel="external nofollow" >',$slabId,'</a>',"</center></td>",
"<td class=td-last><b>アイテム数:</b> ",$slab['number'],'<br/><b>経過時間:</b>',duration($time-$slab['age']),'<br/> <b>退去:</b>',((isset($slab['evicted']) && $slab['evicted']==1)? 'はい':'いいえ');
if ((isset($_GET['dumpslab']) && $_GET['dumpslab']==$slabId) && (isset($_GET['server']) && $_GET['server']==array_search($server,$MEMCACHE_SERVERS))){
echo "<br/><b>アイテム: item</b><br/>";
$items = dumpCacheSlab($server、$slabId、$slab['number']);
// おそらく誰かがここでページネーションをしたいのでしょう :)
$i = 1;
foreach($items['ITEM'] を $itemKey=>$itemInfo として){
$itemInfo = トリム($itemInfo,'[ ]');
echo '<a href="',$PHP_SELF,'&op=4&server=',(array_search($server,$MEMCACHE_SERVERS)),'&key=',base64_encode($itemKey).'" rel="external nofollow" >',$itemKey,'</a>';
($i++ % 10 == 0)の場合{
'<br/>' をエコーします。
}
そうでない場合 ($i!=$slab['number']+1){
エコー ',';
}
}
}
エコー "</td></tr>";
$m=1-$m;
}
エコー <<<EOB
</tbody></table>
</div><hr/>
EOB;
}
壊す;
壊す;
ケース4: //アイテムダンプ
$_GET['key'] が設定されている場合、$_GET['server'] が設定されていないと、
echo "キーが設定されていません!";
壊す;
}
// キー文字列の有効性をチェックするために何もしていません。
// おそらく、key=base64_encode("\n\r delete all") 内のすべてのファイルを削除するエクスプロイトが記述される可能性があります。
// 誰かがこれを修正する必要があります。
$theKey = htmlentities(base64_decode($_GET['key']));
$theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
リスト($h、$p) = 爆発(':'、$theserver);
$r = sendMemcacheCommand($h,$p,'get '.$theKey);
エコー <<<EOB
<div class="info"><テーブルセル間隔=0><tbody>
<tr><th>サーバー<th>キー</th><th>値</th><th>削除</th></tr>
EOB;
echo "<tr><td class=td-0>",$theserver,"</td><td class=td-0>",$theKey,
" <br/>フラグ:",$r['VALUE'][$theKey]['stat']['flag'],
" <br/>サイズ:",bsize($r['VALUE'][$theKey]['stat']['size']),
"</td><td>",chunk_split($r['VALUE'][$theKey]['value'],40),"</td>",
'<td><a href="',$PHP_SELF,'&op=5&server=',(int)$_GET['server'],'&key=',base64_encode($theKey)," rel="external nofollow" \">削除</a></td>","</tr>";
エコー <<<EOB
</tbody></table>
</div><hr/>
EOB;
壊す;
ケース5: // アイテム削除
$_GET['key'] が設定されている場合、$_GET['server'] が設定されていないと、
echo "キーが設定されていません!";
壊す;
}
$theKey = htmlentities(base64_decode($_GET['key']));
$theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
リスト($h、$p) = 爆発(':'、$theserver);
$r = sendMemcacheCommand($h,$p,'delete '.$theKey);
echo '.$theKey.' を削除しています:'.$r;
壊す;
ケース 6: // サーバーをフラッシュする
$theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
$r = $theserver をフラッシュします。
echo 'Flush '.$theserver.":".$r;
壊す;
}
エコー getFooter();
?>
Nginx ベースの Mencached キャッシュ設定の詳細説明に関するこの記事はこれで終わりです。より関連性の高い Nginx Mencached キャッシュ設定コンテンツについては、123WORDPRESS.COM の以前の記事を検索するか、以下の関連記事を引き続き参照してください。今後とも 123WORDPRESS.COM をよろしくお願いいたします。