]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/mcc.php
MediaWiki 1.5.8 (initial commit)
[autoinstalls/mediawiki.git] / maintenance / mcc.php
1 <?php
2 /**
3  * memcached diagnostic tool
4  *
5  * @todo document
6  * @package MediaWiki
7  * @subpackage Maintenance
8  */
9
10 /** */
11 require_once( "commandLine.inc" );
12 require_once("memcached-client.php");
13
14 $mcc = new memcached( array('persistant' => true, 'debug' => true) );
15 $mcc->set_servers( $wgMemCachedServers );
16 $mcc->set_debug( true );
17
18 do {
19         $bad = false;
20         $quit = false;
21         $line = readconsole( "> " );
22         if ($line === false) exit;
23         $args = explode( " ", $line );
24         $command = array_shift( $args );
25         switch ( $command ) {
26                 case "get":
27                         print "Getting {$args[0]}[{$args[1]}]\n";
28                         $res = $mcc->get( $args[0] );
29                         if ( array_key_exists( 1, $args ) ) {
30                                 $res = $res[$args[1]];
31                         }
32                         if ( $res === false ) {
33                                 #print 'Error: ' . $mcc->error_string() . "\n";
34                                 print "MemCached error\n";
35                         } elseif ( is_string( $res ) ) {
36                                 print "$res\n";
37                         } else {
38                                 var_dump( $res );
39                         }
40                         break;
41                 case "getsock":
42                         $res = $mcc->get( $args[0] );
43                         $sock = $mcc->get_sock( $args[0] );
44                         var_dump( $sock );
45                         break;
46                 case "set":
47                         $key = array_shift( $args );
48                         if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
49                                 $value = str_repeat( "*", $args[1] );
50                         } else {
51                                 $value = implode( " ", $args );
52                         }
53                         if ( !$mcc->set( $key, $value, 0 ) ) {
54                                 #print 'Error: ' . $mcc->error_string() . "\n";
55                                 print "MemCached error\n";
56                         }
57                         break;
58                 case "delete":
59                         $key = implode( " ", $args );
60                         if ( !$mcc->delete( $key ) ) {
61                                 #print 'Error: ' . $mcc->error_string() . "\n";
62                                 print "MemCached error\n";
63                         }
64                         break;                                 
65                 case "dumpmcc":
66                         var_dump( $mcc );
67                         break;
68                 case "quit":
69                 case "exit":
70                         $quit = true;
71                         break;
72                 default:
73                         $bad = true;
74         }
75         if ( $bad ) {
76                 if ( $command ) {
77                         print "Bad command\n";
78                 }
79         } else {
80                 if ( function_exists( "readline_add_history" ) ) {
81                         readline_add_history( $line );
82                 }
83         }
84 } while ( !$quit );
85
86 ?>