DBConnection::getReplicateDelay PHP Method

getReplicateDelay() static public method

Get delay between slave and master
static public getReplicateDelay ( $choice = NULL ) : integer
$choice integer, host number (default NULL)
return integer
    static function getReplicateDelay($choice = NULL)
    {
        include_once GLPI_CONFIG_DIR . "/config_db_slave.php";
        return (int) (self::getHistoryMaxDate(new DB()) - self::getHistoryMaxDate(new DBSlave($choice)));
    }

Usage Example

// check_http -H servername -u /glpi/status.php -s GLPI_OK
// Plain text content
header('Content-type: text/plain');
$ok_master = true;
$ok_slave = true;
$ok = true;
// Check slave server connection
if (DBConnection::isDBSlaveActive()) {
    $DBslave = DBConnection::getDBSlaveConf();
    if (is_array($DBslave->dbhost)) {
        $hosts = $DBslave->dbhost;
    } else {
        $hosts = array($DBslave->dbhost);
    }
    foreach ($hosts as $num => $name) {
        $diff = DBConnection::getReplicateDelay($num);
        if (abs($diff) > 1000000000) {
            echo "GLPI_DBSLAVE_{$num}_OFFLINE\n";
            $ok_slave = false;
        } else {
            if (abs($diff) > HOUR_TIMESTAMP) {
                echo "GLPI_DBSLAVE_{$num}_PROBLEM\n";
                $ok_slave = false;
            } else {
                echo "GLPI_DBSLAVE_{$num}_OK\n";
            }
        }
    }
} else {
    echo "No slave DB\n";
}
All Usage Examples Of DBConnection::getReplicateDelay