Index: branches/5.2.x/core/kernel/db/db_connection.php =================================================================== --- branches/5.2.x/core/kernel/db/db_connection.php +++ branches/5.2.x/core/kernel/db/db_connection.php @@ -888,28 +888,25 @@ */ public function getSlaveLag() { - // don't use kDBConnection::Query method, since it will create an array of all server processes - $processes = $this->GetIterator('SHOW PROCESSLIST'); - - $skip_states = Array ( - 'Waiting for master to send event', - 'Connecting to master', - 'Queueing master event to the relay log', - 'Waiting for master update', - 'Requesting binlog dump', - ); - - // find slave SQL thread - foreach ($processes as $process) { - if ( $process['User'] == 'system user' && !in_array($process['State'], $skip_states) ) { - // this is it, return the time (except -ve) + try { + $rows = $this->Query('SHOW SLAVE STATUS'); + } + catch ( RuntimeException $e ) { + // When "SUPER" or "REPLICATION CLIENT" permission is missing. + return 0; + } - return $process['Time'] > 0x7fffffff ? false : $process['Time']; - } + // On the silenced error OR database server isn't configured for a replication. + if ( $rows === false || count($rows) !== 1 ) { + return 0; } - return false; + $row = reset($rows); + + // When slave is too busy catching up with a master we'll get a NULL/empty string here. + return is_numeric($row['Seconds_Behind_Master']) ? $row['Seconds_Behind_Master'] : false; } + }