MediaWiki REL1_33
lag.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
27
33class DatabaseLag extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Shows database lag' );
37 $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
38 }
39
40 public function execute() {
41 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
42 if ( $this->hasOption( 'r' ) ) {
43 echo 'time ';
44
45 $serverCount = $lb->getServerCount();
46 for ( $i = 1; $i < $serverCount; $i++ ) {
47 $hostname = $lb->getServerName( $i );
48 printf( "%-12s ", $hostname );
49 }
50 echo "\n";
51
52 while ( 1 ) {
53 $lags = $lb->getLagTimes();
54 unset( $lags[0] );
55 echo gmdate( 'H:i:s' ) . ' ';
56 foreach ( $lags as $lag ) {
57 printf( "%-12s ", $lag === false ? 'false' : $lag );
58 }
59 echo "\n";
60 sleep( 5 );
61 }
62 } else {
63 $lags = $lb->getLagTimes();
64 foreach ( $lags as $i => $lag ) {
65 $name = $lb->getServerName( $i );
66 $this->output( sprintf( "%-20s %s\n", $name, $lag === false ? 'false' : $lag ) );
67 }
68 }
69 }
70}
71
72$maintClass = DatabaseLag::class;
73require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Maintenance script to show database lag.
Definition lag.php:33
execute()
Do the actual work.
Definition lag.php:40
__construct()
Default constructor.
Definition lag.php:34
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 exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
MediaWikiServices is the service locator for the application scope of MediaWiki.
$maintClass
Definition lag.php:72
require_once RUN_MAINTENANCE_IF_MAIN