ipblocks, recentchanges conversion
[lhc/web/wiklou.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
13 $mcc = new memcached( array('persistant' => true) );
14 $mcc->set_servers( $wgMemCachedServers );
15 $mcc->set_debug( true );
16
17 do {
18 $bad = false;
19 $quit = false;
20 $line = readconsole( "> " );
21 $args = explode( " ", $line );
22 $command = array_shift( $args );
23 switch ( $command ) {
24 case "get":
25 print "Getting {$args[0]}[{$args[1]}]\n";
26 $res = $mcc->get( $args[0] );
27 if ( array_key_exists( 1, $args ) ) {
28 $res = $res[$args[1]];
29 }
30 if ( $res === false ) {
31 #print 'Error: ' . $mcc->error_string() . "\n";
32 print "MemCached error\n";
33 } elseif ( is_string( $res ) ) {
34 print "$res\n";
35 } else {
36 var_dump( $res );
37 }
38 break;
39 case "getsock":
40 $res = $mcc->get( $args[0] );
41 $sock = $mcc->get_sock( $args[0] );
42 var_dump( $sock );
43 break;
44 case "set":
45 $key = array_shift( $args );
46 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
47 $value = str_repeat( "*", $args[1] );
48 } else {
49 $value = implode( " ", $args );
50 }
51 if ( !$mcc->set( $key, $value, 0 ) ) {
52 #print 'Error: ' . $mcc->error_string() . "\n";
53 print "MemCached error\n";
54 }
55 break;
56 case "delete":
57 $key = implode( " ", $args );
58 if ( !$mcc->delete( $key ) ) {
59 #print 'Error: ' . $mcc->error_string() . "\n";
60 print "MemCached error\n";
61 }
62 break;
63 case "dumpmcc":
64 var_dump( $mcc );
65 break;
66 case "quit":
67 case "exit":
68 $quit = true;
69 break;
70 default:
71 $bad = true;
72 }
73 if ( $bad ) {
74 if ( $command ) {
75 print "Bad command\n";
76 }
77 } else {
78 if ( function_exists( "readline_add_history" ) ) {
79 readline_add_history( $line );
80 }
81 }
82 } while ( !$quit );
83
84 ?>