Proof of concept parallel processing with Danga Gearman and PEAR Net_Gearman.
[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( 'commandLine.inc' );
12
13 $mcc = new memcached( 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 print "Getting {$args[0]}[{$args[1]}]\n";
92 $res = $mcc->get( $args[0] );
93 if ( array_key_exists( 1, $args ) ) {
94 $res = $res[$args[1]];
95 }
96 if ( $res === false ) {
97 #print 'Error: ' . $mcc->error_string() . "\n";
98 print "MemCached error\n";
99 } elseif ( is_string( $res ) ) {
100 print "$res\n";
101 } else {
102 var_dump( $res );
103 }
104 break;
105
106 case 'getsock':
107 $res = $mcc->get( $args[0] );
108 $sock = $mcc->get_sock( $args[0] );
109 var_dump( $sock );
110 break;
111
112 case 'server':
113 $res = $mcc->get( $args[0] );
114 $hv = $mcc->_hashfunc( $args[0] );
115 for ( $i = 0; $i < 3; $i++ ) {
116 print $mcc->_buckets[$hv % $mcc->_bucketcount] . "\n";
117 $hv += $mcc->_hashfunc( $i . $args[0] );
118 }
119 break;
120
121 case 'set':
122 $key = array_shift( $args );
123 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
124 $value = str_repeat( '*', $args[1] );
125 } else {
126 $value = implode( ' ', $args );
127 }
128 if ( !$mcc->set( $key, $value, 0 ) ) {
129 #print 'Error: ' . $mcc->error_string() . "\n";
130 print "MemCached error\n";
131 }
132 break;
133
134 case 'delete':
135 $key = implode( ' ', $args );
136 if ( !$mcc->delete( $key ) ) {
137 #print 'Error: ' . $mcc->error_string() . "\n";
138 print "MemCached error\n";
139 }
140 break;
141
142 case 'history':
143 if ( function_exists( 'readline_list_history' ) ) {
144 foreach( readline_list_history() as $num => $line) {
145 print "$num: $line\n";
146 }
147 } else {
148 print "readline_list_history() not available\n";
149 }
150 break;
151
152 case 'dumpmcc':
153 var_dump( $mcc );
154 break;
155
156 case 'quit':
157 case 'exit':
158 $quit = true;
159 break;
160
161 default:
162 $bad = true;
163 } // switch() end
164
165 if ( $bad ) {
166 if ( $command ) {
167 print "Bad command\n";
168 }
169 } else {
170 if ( function_exists( 'readline_add_history' ) ) {
171 readline_add_history( $line );
172 }
173 }
174 } while ( !$quit );
175
176