* Use double quoted consistently on attributes in linker output; preparing for new...
[mediawiki.git] / maintenance / mcc.php
blob93b6ec183ac98b3bb74a0f35aa61e39276ac2873
1 <?php
2 /**
3 * memcached diagnostic tool
5 * @todo document
6 * @package MediaWiki
7 * @subpackage Maintenance
8 */
10 /** */
11 require_once( 'commandLine.inc' );
12 require_once( 'memcached-client.php' );
14 $mcc = new memcached( array('persistant' => true/*, 'debug' => true*/) );
15 $mcc->set_servers( $wgMemCachedServers );
16 #$mcc->set_debug( true );
18 function mccShowHelp($command) {
20 if(! $command ) { $command = 'fullhelp'; }
21 $onlyone = true;
23 switch ( $command ) {
25 case 'fullhelp':
26 // will show help for all commands
27 $onlyone = false;
29 case 'get':
30 print "get: grabs something\n";
31 if($onlyone) { break; }
33 case 'getsock':
34 print "getsock: lists sockets\n";
35 if($onlyone) { break; }
37 case 'set':
38 print "set: changes something\n";
39 if($onlyone) { break; }
41 case 'delete':
42 print "delete: deletes something\n";
43 if($onlyone) { break; }
45 case 'history':
46 print "history: show command line history\n";
47 if($onlyone) { break; }
49 case 'server':
50 print "server: show current memcached server\n";
51 if($onlyone) { break; }
53 case 'dumpmcc':
54 print "dumpmcc: shows the whole thing\n";
55 if($onlyone) { break; }
57 case 'exit':
58 case 'quit':
59 print "exit or quit: exit mcc\n";
60 if($onlyone) { break; }
62 case 'help':
63 print "help: help about a command\n";
64 if($onlyone) { break; }
66 default:
67 if($onlyone) {
68 print "$command: command does not exist or no help for it\n";
73 do {
74 $bad = false;
75 $showhelp = false;
76 $quit = false;
78 $line = readconsole( '> ' );
79 if ($line === false) exit;
81 $args = explode( ' ', $line );
82 $command = array_shift( $args );
84 // process command
85 switch ( $command ) {
86 case 'help':
87 // show an help message
88 mccShowHelp(array_shift($args));
89 break;
91 case 'get':
92 print "Getting {$args[0]}[{$args[1]}]\n";
93 $res = $mcc->get( $args[0] );
94 if ( array_key_exists( 1, $args ) ) {
95 $res = $res[$args[1]];
97 if ( $res === false ) {
98 #print 'Error: ' . $mcc->error_string() . "\n";
99 print "MemCached error\n";
100 } elseif ( is_string( $res ) ) {
101 print "$res\n";
102 } else {
103 var_dump( $res );
105 break;
107 case 'getsock':
108 $res = $mcc->get( $args[0] );
109 $sock = $mcc->get_sock( $args[0] );
110 var_dump( $sock );
111 break;
113 case 'server':
114 $res = $mcc->get( $args[0] );
115 print $mcc->_buckets[$mcc->_hashfunc( $args[0] ) % $mcc->_bucketcount] . "\n";
116 break;
118 case 'set':
119 $key = array_shift( $args );
120 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
121 $value = str_repeat( '*', $args[1] );
122 } else {
123 $value = implode( ' ', $args );
125 if ( !$mcc->set( $key, $value, 0 ) ) {
126 #print 'Error: ' . $mcc->error_string() . "\n";
127 print "MemCached error\n";
129 break;
131 case 'delete':
132 $key = implode( ' ', $args );
133 if ( !$mcc->delete( $key ) ) {
134 #print 'Error: ' . $mcc->error_string() . "\n";
135 print "MemCached error\n";
137 break;
139 case 'history':
140 if ( function_exists( 'readline_list_history' ) ) {
141 foreach( readline_list_history() as $num => $line) {
142 print "$num: $line\n";
144 } else {
145 print "readline_list_history() not available\n";
147 break;
149 case 'dumpmcc':
150 var_dump( $mcc );
151 break;
153 case 'quit':
154 case 'exit':
155 $quit = true;
156 break;
158 default:
159 $bad = true;
160 } // switch() end
162 if ( $bad ) {
163 if ( $command ) {
164 print "Bad command\n";
166 } else {
167 if ( function_exists( 'readline_add_history' ) ) {
168 readline_add_history( $line );
171 } while ( !$quit );