3 * memcached diagnostic tool
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.
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.
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
22 * @ingroup Maintenance
26 require_once( __DIR__
. '/commandLine.inc' );
28 $mcc = new MWMemcached( array( 'persistent' => true ) );
30 if ( $wgMainCacheType === CACHE_MEMCACHED
) {
31 $mcc->set_servers( $wgMemCachedServers );
32 } elseif( isset( $wgObjectCaches[$wgMainCacheType] ) ) {
33 $mcc->set_servers( $wgObjectCaches[$wgMainCacheType]['servers'] );
35 print "MediaWiki isn't configured for Memcached usage\n";
39 function mccShowHelp( $command ) {
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',
50 'help' => 'help about a command',
53 $command = 'fullhelp';
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 );
60 } elseif ( isset( $commandList[$command] ) ) {
61 print "$command: $commandList[$command]\n";
63 print "$command: command does not exist or no help for it\n";
72 $line = Maintenance
::readconsole();
73 if ( $line === false ) exit;
75 $args = explode( ' ', $line );
76 $command = array_shift( $args );
81 // show an help message
82 mccShowHelp( array_shift( $args ) );
87 if ( array_key_exists( 1, $args ) ) {
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]];
95 if ( $res === false ) {
96 # print 'Error: ' . $mcc->error_string() . "\n";
97 print "MemCached error\n";
98 } elseif ( is_string( $res ) ) {
106 $res = $mcc->get( $args[0] );
107 $sock = $mcc->get_sock( $args[0] );
112 if ( $mcc->_single_sock
!== null ) {
113 print $mcc->_single_sock
. "\n";
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] );
125 $key = array_shift( $args );
126 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
127 $value = str_repeat( '*', $args[1] );
129 $value = implode( ' ', $args );
131 if ( !$mcc->set( $key, $value, 0 ) ) {
132 # print 'Error: ' . $mcc->error_string() . "\n";
133 print "MemCached error\n";
138 $key = implode( ' ', $args );
139 if ( !$mcc->delete( $key ) ) {
140 # print 'Error: ' . $mcc->error_string() . "\n";
141 print "MemCached error\n";
146 if ( function_exists( 'readline_list_history' ) ) {
147 foreach ( readline_list_history() as $num => $line ) {
148 print "$num: $line\n";
151 print "readline_list_history() not available\n";
170 print "Bad command\n";
173 if ( function_exists( 'readline_add_history' ) ) {
174 readline_add_history( $line );