When saving preferences, check hook and authentication plugin, and actually save...
[mediawiki.git] / maintenance / mcc.php
blob97a344fb24cfb1e928d7fcf738460c439274134d
1 <?php
2 /**
3 * memcached diagnostic tool
5 * @todo document
6 * @addtogroup Maintenance
7 */
9 /** */
10 require_once( 'commandLine.inc' );
12 $mcc = new memcached( array('persistant' => true/*, 'debug' => true*/) );
13 $mcc->set_servers( $wgMemCachedServers );
14 #$mcc->set_debug( true );
16 function mccShowHelp($command) {
18 if(! $command ) { $command = 'fullhelp'; }
19 $onlyone = true;
21 switch ( $command ) {
23 case 'fullhelp':
24 // will show help for all commands
25 $onlyone = false;
27 case 'get':
28 print "get: grabs something\n";
29 if($onlyone) { break; }
31 case 'getsock':
32 print "getsock: lists sockets\n";
33 if($onlyone) { break; }
35 case 'set':
36 print "set: changes something\n";
37 if($onlyone) { break; }
39 case 'delete':
40 print "delete: deletes something\n";
41 if($onlyone) { break; }
43 case 'history':
44 print "history: show command line history\n";
45 if($onlyone) { break; }
47 case 'server':
48 print "server: show current memcached server\n";
49 if($onlyone) { break; }
51 case 'dumpmcc':
52 print "dumpmcc: shows the whole thing\n";
53 if($onlyone) { break; }
55 case 'exit':
56 case 'quit':
57 print "exit or quit: exit mcc\n";
58 if($onlyone) { break; }
60 case 'help':
61 print "help: help about a command\n";
62 if($onlyone) { break; }
64 default:
65 if($onlyone) {
66 print "$command: command does not exist or no help for it\n";
71 do {
72 $bad = false;
73 $showhelp = false;
74 $quit = false;
76 $line = readconsole( '> ' );
77 if ($line === false) exit;
79 $args = explode( ' ', $line );
80 $command = array_shift( $args );
82 // process command
83 switch ( $command ) {
84 case 'help':
85 // show an help message
86 mccShowHelp(array_shift($args));
87 break;
89 case 'get':
90 print "Getting {$args[0]}[{$args[1]}]\n";
91 $res = $mcc->get( $args[0] );
92 if ( array_key_exists( 1, $args ) ) {
93 $res = $res[$args[1]];
95 if ( $res === false ) {
96 #print 'Error: ' . $mcc->error_string() . "\n";
97 print "MemCached error\n";
98 } elseif ( is_string( $res ) ) {
99 print "$res\n";
100 } else {
101 var_dump( $res );
103 break;
105 case 'getsock':
106 $res = $mcc->get( $args[0] );
107 $sock = $mcc->get_sock( $args[0] );
108 var_dump( $sock );
109 break;
111 case 'server':
112 $res = $mcc->get( $args[0] );
113 $hv = $mcc->_hashfunc( $args[0] );
114 for ( $i = 0; $i < 3; $i++ ) {
115 print $mcc->_buckets[$hv % $mcc->_bucketcount] . "\n";
116 $hv += $mcc->_hashfunc( $i . $args[0] );
118 break;
120 case 'set':
121 $key = array_shift( $args );
122 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
123 $value = str_repeat( '*', $args[1] );
124 } else {
125 $value = implode( ' ', $args );
127 if ( !$mcc->set( $key, $value, 0 ) ) {
128 #print 'Error: ' . $mcc->error_string() . "\n";
129 print "MemCached error\n";
131 break;
133 case 'delete':
134 $key = implode( ' ', $args );
135 if ( !$mcc->delete( $key ) ) {
136 #print 'Error: ' . $mcc->error_string() . "\n";
137 print "MemCached error\n";
139 break;
141 case 'history':
142 if ( function_exists( 'readline_list_history' ) ) {
143 foreach( readline_list_history() as $num => $line) {
144 print "$num: $line\n";
146 } else {
147 print "readline_list_history() not available\n";
149 break;
151 case 'dumpmcc':
152 var_dump( $mcc );
153 break;
155 case 'quit':
156 case 'exit':
157 $quit = true;
158 break;
160 default:
161 $bad = true;
162 } // switch() end
164 if ( $bad ) {
165 if ( $command ) {
166 print "Bad command\n";
168 } else {
169 if ( function_exists( 'readline_add_history' ) ) {
170 readline_add_history( $line );
173 } while ( !$quit );