Support for systems without readline
[lhc/web/wiklou.git] / maintenance / mcc.php
1 <?php
2 include_once( "../includes/DefaultSettings.php" );
3 include_once( "../LocalSettings.php" );
4 include_once( "../includes/MemCachedClient.inc.php" );
5
6 $mcc = new MemCachedClient();
7 $mcc->set_servers( $wgMemCachedServers );
8
9 do {
10 $bad = false;
11 $quit = false;
12 $line = readconsole( "> " );
13 $args = explode( " ", $line );
14 $command = array_shift( $args );
15 switch ( $command ) {
16 case "get":
17 $res = $mcc->get( implode( " ", $args ) );
18 if ( $res === false ) {
19 print 'Error: ' . $mcc->error_string() . "\n";
20 } elseif ( is_string( $res ) ) {
21 print "$res\n";
22 } else {
23 var_dump( $res );
24 }
25 break;
26 case "set":
27 $key = array_shift( $args );
28 if ( !$mcc->set( $key, implode( " ", $args ), 0 ) ) {
29 print 'Error: ' . $mcc->error_string() . "\n";
30 }
31 break;
32 case "quit":
33 $quit = true;
34 break;
35 default:
36 $bad = true;
37 }
38 if ( $bad ) {
39 if ( $command ) {
40 print "Bad command\n";
41 }
42 } else {
43 if ( function_exists( "readline_add_history" ) ) {
44 readline_add_history( $line );
45 }
46 }
47 } while ( !$quit );
48
49 function readconsole( $prompt = "" ) {
50 if ( function_exists( "readline" ) ) {
51 return readline( $prompt );
52 } else {
53 print $prompt;
54 $fp = fopen( "php://stdin", "r" );
55 $resp = trim( fgets( $fp, 1024 ) );
56 fclose( $fp );
57 return $resp;
58 }
59 }
60
61
62
63 ?>
64