updated to work with new client
[lhc/web/wiklou.git] / maintenance / mcc.php
1 <?php
2 /*require_once( "../includes/DefaultSettings.php" );
3 require_once( "../LocalSettings.php" );
4 require_once( "../includes/MemCachedClient.inc.php" );*/
5
6
7 require_once( "liveCmdLine.inc" );
8
9 $mcc = new memcached( array('persistant' => true) );
10 $mcc->set_servers( $wgMemCachedServers );
11 $mcc->set_debug( true );
12
13 do {
14 $bad = false;
15 $quit = false;
16 $line = readconsole( "> " );
17 $args = explode( " ", $line );
18 $command = array_shift( $args );
19 switch ( $command ) {
20 case "get":
21 print "Getting {$args[0]}[{$args[1]}]\n";
22 $res = $mcc->get( $args[0] );
23 if ( array_key_exists( 1, $args ) ) {
24 $res = $res[$args[1]];
25 }
26 if ( $res === false ) {
27 #print 'Error: ' . $mcc->error_string() . "\n";
28 print "MemCached error\n";
29 } elseif ( is_string( $res ) ) {
30 print "$res\n";
31 } else {
32 var_dump( $res );
33 }
34 break;
35 case "set":
36 $key = array_shift( $args );
37 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
38 $value = str_repeat( "*", $args[1] );
39 } else {
40 $value = implode( " ", $args );
41 }
42 if ( !$mcc->set( $key, $value, 0 ) ) {
43 #print 'Error: ' . $mcc->error_string() . "\n";
44 print "MemCached error\n";
45 }
46 break;
47 case "delete":
48 $key = implode( " ", $args );
49 if ( !$mcc->delete( $key ) ) {
50 #print 'Error: ' . $mcc->error_string() . "\n";
51 print "MemCached error\n";
52 }
53 break;
54 case "quit":
55 $quit = true;
56 break;
57 default:
58 $bad = true;
59 }
60 if ( $bad ) {
61 if ( $command ) {
62 print "Bad command\n";
63 }
64 } else {
65 if ( function_exists( "readline_add_history" ) ) {
66 readline_add_history( $line );
67 }
68 }
69 } while ( !$quit );
70
71 function readconsole( $prompt = "" ) {
72 if ( function_exists( "readline" ) ) {
73 return readline( $prompt );
74 } else {
75 print $prompt;
76 $fp = fopen( "php://stdin", "r" );
77 $resp = trim( fgets( $fp, 1024 ) );
78 fclose( $fp );
79 return $resp;
80 }
81 }
82
83
84
85 ?>
86