Followup to r59869, add to MySQL section, and copy patch to SQLite directory
[lhc/web/wiklou.git] / maintenance / mcc.php
1 <?php
2 /**
3 * memcached diagnostic tool
4 *
5 * @file
6 * @todo document
7 * @ingroup Maintenance
8 */
9
10 /** */
11 require_once( dirname(__FILE__) . '/commandLine.inc' );
12
13 $mcc = new MWMemcached( array('persistant' => true/*, 'debug' => true*/) );
14 $mcc->set_servers( $wgMemCachedServers );
15 #$mcc->set_debug( true );
16
17 function mccShowHelp($command) {
18
19 if(! $command ) { $command = 'fullhelp'; }
20 $onlyone = true;
21
22 switch ( $command ) {
23
24 case 'fullhelp':
25 // will show help for all commands
26 $onlyone = false;
27
28 case 'get':
29 print "get: grabs something\n";
30 if($onlyone) { break; }
31
32 case 'getsock':
33 print "getsock: lists sockets\n";
34 if($onlyone) { break; }
35
36 case 'set':
37 print "set: changes something\n";
38 if($onlyone) { break; }
39
40 case 'delete':
41 print "delete: deletes something\n";
42 if($onlyone) { break; }
43
44 case 'history':
45 print "history: show command line history\n";
46 if($onlyone) { break; }
47
48 case 'server':
49 print "server: show current memcached server\n";
50 if($onlyone) { break; }
51
52 case 'dumpmcc':
53 print "dumpmcc: shows the whole thing\n";
54 if($onlyone) { break; }
55
56 case 'exit':
57 case 'quit':
58 print "exit or quit: exit mcc\n";
59 if($onlyone) { break; }
60
61 case 'help':
62 print "help: help about a command\n";
63 if($onlyone) { break; }
64
65 default:
66 if($onlyone) {
67 print "$command: command does not exist or no help for it\n";
68 }
69 }
70 }
71
72 do {
73 $bad = false;
74 $showhelp = false;
75 $quit = false;
76
77 $line = readconsole( '> ' );
78 if ($line === false) exit;
79
80 $args = explode( ' ', $line );
81 $command = array_shift( $args );
82
83 // process command
84 switch ( $command ) {
85 case 'help':
86 // show an help message
87 mccShowHelp(array_shift($args));
88 break;
89
90 case 'get':
91 $sub = '';
92 if ( array_key_exists( 1, $args ) ) {
93 $sub = $args[1];
94 }
95 print "Getting {$args[0]}[$sub]\n";
96 $res = $mcc->get( $args[0] );
97 if ( array_key_exists( 1, $args ) ) {
98 $res = $res[$args[1]];
99 }
100 if ( $res === false ) {
101 #print 'Error: ' . $mcc->error_string() . "\n";
102 print "MemCached error\n";
103 } elseif ( is_string( $res ) ) {
104 print "$res\n";
105 } else {
106 var_dump( $res );
107 }
108 break;
109
110 case 'getsock':
111 $res = $mcc->get( $args[0] );
112 $sock = $mcc->get_sock( $args[0] );
113 var_dump( $sock );
114 break;
115
116 case 'server':
117 $res = $mcc->get( $args[0] );
118 $hv = $mcc->_hashfunc( $args[0] );
119 for ( $i = 0; $i < 3; $i++ ) {
120 print $mcc->_buckets[$hv % $mcc->_bucketcount] . "\n";
121 $hv += $mcc->_hashfunc( $i . $args[0] );
122 }
123 break;
124
125 case 'set':
126 $key = array_shift( $args );
127 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
128 $value = str_repeat( '*', $args[1] );
129 } else {
130 $value = implode( ' ', $args );
131 }
132 if ( !$mcc->set( $key, $value, 0 ) ) {
133 #print 'Error: ' . $mcc->error_string() . "\n";
134 print "MemCached error\n";
135 }
136 break;
137
138 case 'delete':
139 $key = implode( ' ', $args );
140 if ( !$mcc->delete( $key ) ) {
141 #print 'Error: ' . $mcc->error_string() . "\n";
142 print "MemCached error\n";
143 }
144 break;
145
146 case 'history':
147 if ( function_exists( 'readline_list_history' ) ) {
148 foreach( readline_list_history() as $num => $line) {
149 print "$num: $line\n";
150 }
151 } else {
152 print "readline_list_history() not available\n";
153 }
154 break;
155
156 case 'dumpmcc':
157 var_dump( $mcc );
158 break;
159
160 case 'quit':
161 case 'exit':
162 $quit = true;
163 break;
164
165 default:
166 $bad = true;
167 } // switch() end
168
169 if ( $bad ) {
170 if ( $command ) {
171 print "Bad command\n";
172 }
173 } else {
174 if ( function_exists( 'readline_add_history' ) ) {
175 readline_add_history( $line );
176 }
177 }
178 } while ( !$quit );
179
180