Add a comment explaining what this is for :)
[lhc/web/wiklou.git] / maintenance / mcc.php
1 <?php
2
3 # memcached diagnostic tool
4
5 require_once( "commandLine.inc" );
6
7 $mcc = new memcached( array('persistant' => true) );
8 $mcc->set_servers( $wgMemCachedServers );
9 $mcc->set_debug( true );
10
11 do {
12 $bad = false;
13 $quit = false;
14 $line = readconsole( "> " );
15 $args = explode( " ", $line );
16 $command = array_shift( $args );
17 switch ( $command ) {
18 case "get":
19 print "Getting {$args[0]}[{$args[1]}]\n";
20 $res = $mcc->get( $args[0] );
21 if ( array_key_exists( 1, $args ) ) {
22 $res = $res[$args[1]];
23 }
24 if ( $res === false ) {
25 #print 'Error: ' . $mcc->error_string() . "\n";
26 print "MemCached error\n";
27 } elseif ( is_string( $res ) ) {
28 print "$res\n";
29 } else {
30 var_dump( $res );
31 }
32 break;
33 case "set":
34 $key = array_shift( $args );
35 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
36 $value = str_repeat( "*", $args[1] );
37 } else {
38 $value = implode( " ", $args );
39 }
40 if ( !$mcc->set( $key, $value, 0 ) ) {
41 #print 'Error: ' . $mcc->error_string() . "\n";
42 print "MemCached error\n";
43 }
44 break;
45 case "delete":
46 $key = implode( " ", $args );
47 if ( !$mcc->delete( $key ) ) {
48 #print 'Error: ' . $mcc->error_string() . "\n";
49 print "MemCached error\n";
50 }
51 break;
52 case "quit":
53 $quit = true;
54 break;
55 default:
56 $bad = true;
57 }
58 if ( $bad ) {
59 if ( $command ) {
60 print "Bad command\n";
61 }
62 } else {
63 if ( function_exists( "readline_add_history" ) ) {
64 readline_add_history( $line );
65 }
66 }
67 } while ( !$quit );
68
69 ?>