pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by Anthony on Fri 1 May 15:20
report abuse | download | new post

  1. <?php
  2. /*
  3.  This application will connect to the memcached daemons found in the $daemons array and do a raw "stats" command and then
  4.  pump that data out via echo commands.
  5.  
  6.  ant92083 {at} gmail {dot} com
  7.  5/1/09
  8. */
  9.  
  10. $host = 'localhost';
  11. // the array is built port=>type
  12. $daemons = array(
  13.     '11211' => 'page',
  14.     '11212' => 'default',
  15.     '11213' => 'content',
  16.     '11214' => 'filter',
  17.     '11215' => 'menu',
  18.     '11216' => 'views'
  19.     );
  20.  
  21. // loop through the $daemons array
  22.  
  23. echo "<table><tr>";
  24.  
  25. foreach($daemons as $port=>$type)
  26. {
  27.   echo "<td>";
  28.   echo "<h1>{$host}:{$port} $type</h1>";
  29.  
  30.   $socket = fsockopen($host, $port);
  31.   if(!$socket)
  32.   {
  33.     echo "<h2 style='color: red;'>Error getting connection to {$host}:{$port}</h2>";
  34.   }
  35.   else
  36.   {
  37.     // issue our command to the memcached daemon
  38.     $bytes = fwrite($socket, "stats\n");
  39.     if($bytes <= 0)
  40.     {
  41.       echo "<h2 style'color: red;'>Error sending \'stats\' command to {$host}:{$port}</h2>";
  42.     }
  43.     // kill our telnet connection
  44.     $bytes = fwrite($socket, "quit\n");
  45.     if($bytes <= 0)
  46.     {
  47.       echo "<h2 style'color: red;'>Error sending \'quit\' command to {$host}:{$port}</h2>";
  48.     }
  49.  
  50.     while (!feof($socket)) {
  51.       $string = fgets($socket, 1024)."<br>\n";
  52.       $string = str_replace("STAT ", '', $string);
  53.       $string = str_replace("END", '', $string);
  54.  
  55.       $string = explode(' ', $string);
  56.       $string = implode(': ', $string);
  57.       echo $string;
  58.     }
  59.  
  60.  
  61.     fclose($socket);
  62.     echo "</td>";
  63.   }
  64. }
  65.  
  66. echo "</tr></table>";
  67. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post