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 } else { 00036 if( $this->hasOption('group') ) { 00037 $db = wfGetDB( DB_SLAVE, $this->getOption('group') ); 00038 $host = $db->getServer(); 00039 } else { 00040 $lb = wfGetLB(); 00041 $i = $lb->getReaderIndex(); 00042 $host = $lb->getServerName( $i ); 00043 } 00044 } 00045 $this->output( "$host\n" ); 00046 } 00047 } 00048 00049 $maintClass = "GetSlaveServer"; 00050 require_once( DO_MAINTENANCE );