PHP监测Memcache服务端的运行状况(8)

foreach($entries as $slabId => $slab) {
      $dumpUrl = $PHP_SELF.'&op=2&server='.(array_search($server,$MEMCACHE_SERVERS)).'&dumpslab='.$slabId;
    echo
     "<tr$m>",
     "<td><center>",'<a href="'https://www.linuxidc.com/,$dumpUrl,'">',$slabId,'</a>',"</center></td>",
     "<td><b>Item count:</b> ",$slab['number'],'<br/><b>Age:</b>',duration($time-$slab['age']),'<br/> <b>Evicted:</b>',((isset($slab['evicted']) && $slab['evicted']==1)? 'Yes':'No');
     if ((isset($_GET['dumpslab']) && $_GET['dumpslab']==$slabId) &&  (isset($_GET['server']) && $_GET['server']==array_search($server,$MEMCACHE_SERVERS))){
        echo "<br/><b>Items: item</b><br/>";
        $items = dumpCacheSlab($server,$slabId,$slab['number']);
                        // maybe someone likes to do a pagination here :)
        $i=1;
                        foreach($items['ITEM'] as $itemKey=>$itemInfo){
                            $itemInfo = trim($itemInfo,'[ ]');


                            echo '<a href="'https://www.linuxidc.com/,$PHP_SELF,'&op=4&server=',(array_search($server,$MEMCACHE_SERVERS)),'&key=',base64_encode($itemKey).'">',$itemKey,'</a>';
                            if ($i++ % 10 == 0) {
                                echo '<br/>';
                            }
                            elseif ($i!=$slab['number']+1){
                                echo ',';
                            }
                        }
     }

echo "</td></tr>";
    $m=1-$m;
   }
  echo <<<EOB
   </tbody></table>
   </div><hr/>
EOB;
}
  break;

break;

case 4: //item dump
        if (!isset($_GET['key']) || !isset($_GET['server'])){
            echo "No key set!";
            break;
        }
        // I'm not doing anything to check the validity of the key string.
        // probably an exploit can be written to delete all the files in key=base64_encode("\n\r delete all").
        // somebody has to do a fix to this.
        $theKey = htmlentities(base64_decode($_GET['key']));

$theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
        list($h,$p) = explode(':',$theserver);
        $r = sendMemcacheCommand($h,$p,'get '.$theKey);
        echo <<<EOB
        <div><table cellspacing=0><tbody>
   <tr><th>Server<th>Key</th><th>Value</th><th>Delete</th></tr>
EOB;
        echo "<tr><td>",$theserver,"</td><td>",$theKey,
            " <br/>flag:",$r['VALUE'][$theKey]['stat']['flag'],
            " <br/>Size:",bsize($r['VALUE'][$theKey]['stat']['size']),
            "</td><td>",chunk_split($r['VALUE'][$theKey]['value'],40),"</td>",
            '<td><a href="'https://www.linuxidc.com/,$PHP_SELF,'&op=5&server=',(int)$_GET['server'],'&key=',base64_encode($theKey),"https://www.linuxidc.com/Linux/2014-11/\">Delete</a></td>","</tr>";
        echo <<<EOB
   </tbody></table>
   </div><hr/>
EOB;
    break;
    case 5: // item delete
     if (!isset($_GET['key']) || !isset($_GET['server'])){
   echo "No key set!";
   break;
        }
        $theKey = htmlentities(base64_decode($_GET['key']));
  $theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
  list($h,$p) = explode(':',$theserver);
        $r = sendMemcacheCommand($h,$p,'delete '.$theKey);
        echo 'Deleting '.$theKey.':'.$r;
 break;
   
  case 6: // flush server
        $theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
        $r = flushServer($theserver);
        echo 'Flush  '.$theserver.":".$r;
  break;
}
echo getFooter();

?>

Memcached 安装及启动脚本

PHP中使用Memcached的性能问题

Ubuntu下安装Memcached及命令解释

Memcached的安装和应用

使用Nginx+Memcached的小图片存储方案

Memcached使用入门

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8864f323703fffce391c0cd784e04a30.html