Anthony
By: a guest | May 1st, 2009 | Syntax:
PHP | Size: 1.54 KB | Hits: 36 | Expires: Never
<?php
/*
This application will connect to the memcached daemons found in the $daemons array and do a raw "stats" command and then
pump that data out via echo commands.
ant92083 {at} gmail {dot} com
5/1/09
*/
$host = 'localhost';
// the array is built port=>type
'11211' => 'page',
'11212' => 'default',
'11213' => 'content',
'11214' => 'filter',
'11215' => 'menu',
'11216' => 'views'
);
// loop through the $daemons array
echo "<table><tr>";
foreach($daemons as $port=>$type)
{
echo "<td>";
echo "<h1>{$host}:{$port} $type</h1>";
if(!$socket)
{
echo "<h2 style='color: red;'>Error getting connection to {$host}:{$port}</h2>";
}
else
{
// issue our command to the memcached daemon
$bytes = fwrite($socket, "stats\n");
if($bytes <= 0)
{
echo "<h2 style'color: red;'>Error sending \'stats\' command to {$host}:{$port}</h2>";
}
// kill our telnet connection
$bytes = fwrite($socket, "quit\n");
if($bytes <= 0)
{
echo "<h2 style'color: red;'>Error sending \'quit\' command to {$host}:{$port}</h2>";
}
$string = fgets($socket, 1024)."<br>\n";
echo $string;
}
echo "</td>";
}
}
echo "</tr></table>";
?>