DBConnection::showAllReplicateDelay PHP Method

showAllReplicateDelay() static public method

Display in HTML, delay between master and slave 1 line per slave is multiple
static public showAllReplicateDelay ( )
    static function showAllReplicateDelay()
    {
        $DBslave = self::getDBSlaveConf();
        if (is_array($DBslave->dbhost)) {
            $hosts = $DBslave->dbhost;
        } else {
            $hosts = array($DBslave->dbhost);
        }
        foreach ($hosts as $num => $name) {
            $diff = self::getReplicateDelay($num);
            //TRANS: %s is namez of server Mysql
            printf(__('%1$s: %2$s'), __('SQL server'), $name);
            echo " - ";
            if ($diff > 1000000000) {
                echo __("can't connect to the database") . "<br>";
            } else {
                if ($diff) {
                    printf(__('%1$s: %2$s') . "<br>", __('Difference between master and slave'), Html::timestampToString($diff, 1));
                } else {
                    printf(__('%1$s: %2$s') . "<br>", __('Difference between master and slave'), __('None'));
                }
            }
        }
    }

Usage Example

 /**
  * Print the config form for slave DB
  *
  * @return Nothing (display)
  **/
 function showFormDBSlave()
 {
     global $DB, $CFG_GLPI, $DBslave;
     if (!Config::canUpdate()) {
         return false;
     }
     echo "<form name='form' action=\"" . Toolbox::getItemTypeFormURL(__CLASS__) . "\" method='post'>";
     echo "<div class='center' id='tabsbody'>";
     echo "<input type='hidden' name='_dbslave_status' value='1'>";
     echo "<table class='tab_cadre_fixe'>";
     $active = DBConnection::isDBSlaveActive();
     echo "<tr class='tab_bg_2'><th colspan='4'>" . _n('Mysql replica', 'Mysql replicas', Session::getPluralNumber()) . "</th></tr>";
     $DBslave = DBConnection::getDBSlaveConf();
     if (is_array($DBslave->dbhost)) {
         $host = implode(' ', $DBslave->dbhost);
     } else {
         $host = $DBslave->dbhost;
     }
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Mysql server') . "</td>";
     echo "<td><input type='text' name='_dbreplicate_dbhost' size='40' value='{$host}'></td>";
     echo "<td>" . __('Database') . "</td>";
     echo "<td><input type='text' name='_dbreplicate_dbdefault' value='" . $DBslave->dbdefault . "'>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Mysql user') . "</td>";
     echo "<td><input type='text' name='_dbreplicate_dbuser' value='" . $DBslave->dbuser . "'></td>";
     echo "<td>" . __('Mysql password') . "</td>";
     echo "<td><input type='password' name='_dbreplicate_dbpassword' value='" . rawurldecode($DBslave->dbpassword) . "'>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Use the slave for the search engine') . "</td><td>";
     $values = array(0 => __('Never'), 1 => __('If synced (all changes)'), 2 => __('If synced (current user changes)'), 3 => __('If synced or read-only account'), 4 => __('Always'));
     Dropdown::showFromArray('use_slave_for_search', $values, array('value' => $CFG_GLPI["use_slave_for_search"]));
     echo "<td colspan='2'>&nbsp;</td>";
     echo "</tr>";
     if ($DBslave->connected && !$DB->isSlave()) {
         echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
         DBConnection::showAllReplicateDelay();
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
     echo "<input type='submit' name='update' class='submit' value=\"" . _sx('button', 'Save') . "\">";
     echo "</td></tr>";
     echo "</table></div>";
     Html::closeForm();
 }
All Usage Examples Of DBConnection::showAllReplicateDelay