MediaWiki  REL1_19
getSlaveServer.php
Go to the documentation of this file.
00001 <?php
00023 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
00024 
00025 class GetSlaveServer extends Maintenance {
00026         public function __construct() {
00027                 parent::__construct();
00028                 $this->addOption( "group", "Query group to check specifically" );
00029                 $this->mDescription = "Report the hostname of a slave server";
00030         }
00031         public function execute() {
00032                 global $wgAllDBsAreLocalhost;
00033                 if ( $wgAllDBsAreLocalhost ) {
00034                         $host = 'localhost';
00035                 } elseif ( $this->hasOption( 'group' ) ) {
00036                         $db = wfGetDB( DB_SLAVE, $this->getOption( 'group' ) );
00037                         $host = $db->getServer();
00038                 } else {
00039                         $lb = wfGetLB();
00040                         $i = $lb->getReaderIndex();
00041                         $host = $lb->getServerName( $i );
00042                 }
00043                 $this->output( "$host\n" );
00044         }
00045 }
00046 
00047 $maintClass = "GetSlaveServer";
00048 require_once( RUN_MAINTENANCE_IF_MAIN );