Make redirect update in refreshLinks.php bypass the redirect table
[lhc/web/wiklou.git] / maintenance / mcc.php
1 <?php
2 /**
3 * memcached diagnostic tool
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @todo document
22 * @ingroup Maintenance
23 */
24
25 /** */
26 require_once( __DIR__ . '/commandLine.inc' );
27
28 $mcc = new MWMemcached( array( 'persistent' => true ) );
29
30 if ( $wgMainCacheType === CACHE_MEMCACHED ) {
31 $mcc->set_servers( $wgMemCachedServers );
32 } elseif( isset( $wgObjectCaches[$wgMainCacheType] ) ) {
33 $mcc->set_servers( $wgObjectCaches[$wgMainCacheType]['servers'] );
34 } else {
35 print "MediaWiki isn't configured for Memcached usage\n";
36 exit( 1 );
37 }
38
39 function mccShowHelp( $command ) {
40 $commandList = array(
41 'get' => 'grabs something',
42 'getsock' => 'lists sockets',
43 'set' => 'changes something',
44 'delete' => 'deletes something',
45 'history' => 'show command line history',
46 'server' => 'show current memcached server',
47 'dumpmcc' => 'shows the whole thing',
48 'exit' => 'exit mcc',
49 'quit' => 'exit mcc',
50 'help' => 'help about a command',
51 );
52 if ( !$command ) {
53 $command = 'fullhelp';
54 }
55 if ( $command === 'fullhelp' ) {
56 $max_cmd_len = max( array_map( 'strlen', array_keys( $commandList ) ) );
57 foreach ( $commandList as $cmd => $desc ) {
58 printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc );
59 }
60 } elseif ( isset( $commandList[$command] ) ) {
61 print "$command: $commandList[$command]\n";
62 } else {
63 print "$command: command does not exist or no help for it\n";
64 }
65 }
66
67 do {
68 $bad = false;
69 $showhelp = false;
70 $quit = false;
71
72 $line = Maintenance::readconsole();
73 if ( $line === false ) exit;
74
75 $args = explode( ' ', $line );
76 $command = array_shift( $args );
77
78 // process command
79 switch ( $command ) {
80 case 'help':
81 // show an help message
82 mccShowHelp( array_shift( $args ) );
83 break;
84
85 case 'get':
86 $sub = '';
87 if ( array_key_exists( 1, $args ) ) {
88 $sub = $args[1];
89 }
90 print "Getting {$args[0]}[$sub]\n";
91 $res = $mcc->get( $args[0] );
92 if ( array_key_exists( 1, $args ) ) {
93 $res = $res[$args[1]];
94 }
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 );
102 }
103 break;
104
105 case 'getsock':
106 $res = $mcc->get( $args[0] );
107 $sock = $mcc->get_sock( $args[0] );
108 var_dump( $sock );
109 break;
110
111 case 'server':
112 if ( $mcc->_single_sock !== null ) {
113 print $mcc->_single_sock . "\n";
114 break;
115 }
116 $res = $mcc->get( $args[0] );
117 $hv = $mcc->_hashfunc( $args[0] );
118 for ( $i = 0; $i < 3; $i++ ) {
119 print $mcc->_buckets[$hv % $mcc->_bucketcount] . "\n";
120 $hv += $mcc->_hashfunc( $i . $args[0] );
121 }
122 break;
123
124 case 'set':
125 $key = array_shift( $args );
126 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
127 $value = str_repeat( '*', $args[1] );
128 } else {
129 $value = implode( ' ', $args );
130 }
131 if ( !$mcc->set( $key, $value, 0 ) ) {
132 # print 'Error: ' . $mcc->error_string() . "\n";
133 print "MemCached error\n";
134 }
135 break;
136
137 case 'delete':
138 $key = implode( ' ', $args );
139 if ( !$mcc->delete( $key ) ) {
140 # print 'Error: ' . $mcc->error_string() . "\n";
141 print "MemCached error\n";
142 }
143 break;
144
145 case 'history':
146 if ( function_exists( 'readline_list_history' ) ) {
147 foreach ( readline_list_history() as $num => $line ) {
148 print "$num: $line\n";
149 }
150 } else {
151 print "readline_list_history() not available\n";
152 }
153 break;
154
155 case 'dumpmcc':
156 var_dump( $mcc );
157 break;
158
159 case 'quit':
160 case 'exit':
161 $quit = true;
162 break;
163
164 default:
165 $bad = true;
166 } // switch() end
167
168 if ( $bad ) {
169 if ( $command ) {
170 print "Bad command\n";
171 }
172 } else {
173 if ( function_exists( 'readline_add_history' ) ) {
174 readline_add_history( $line );
175 }
176 }
177 } while ( !$quit );