MediaWiki REL1_41
lag.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
31class DatabaseLag extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->addDescription( 'Shows database lag' );
35 $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
36 }
37
38 public function execute() {
39 $lb = $this->getServiceContainer()->getDBLoadBalancer();
40 if ( $this->hasOption( 'r' ) ) {
41 $this->output( 'time ' );
42
43 $serverCount = $lb->getServerCount();
44 for ( $i = 1; $i < $serverCount; $i++ ) {
45 $hostname = $lb->getServerName( $i );
46 $this->output( sprintf( "%-12s ", $hostname ) );
47 }
48 $this->output( "\n" );
49
50 // @phan-suppress-next-line PhanInfiniteLoop
51 while ( 1 ) {
52 $lags = $lb->getLagTimes();
53 unset( $lags[0] );
54 $this->output( gmdate( 'H:i:s' ) . ' ' );
55 foreach ( $lags as $lag ) {
56 $this->output( sprintf( "%-12s ", $lag === false ? 'false' : $lag ) );
57 }
58 $this->output( "\n" );
59 sleep( 5 );
60 }
61 } else {
62 $lags = $lb->getLagTimes();
63 foreach ( $lags as $i => $lag ) {
64 $name = $lb->getServerName( $i );
65 $this->output( sprintf( "%-20s %s\n", $name, $lag === false ? 'false' : $lag ) );
66 }
67 }
68 }
69}
70
71$maintClass = DatabaseLag::class;
72require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to show database lag.
Definition lag.php:31
execute()
Do the actual work.
Definition lag.php:38
__construct()
Default constructor.
Definition lag.php:32
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$maintClass
Definition lag.php:71