HyperDB icon indicating copy to clipboard operation
HyperDB copied to clipboard

PHP Notice: Undefined index: global__r

Open sanchit-hwd opened this issue 2 years ago • 1 comments

PHP Notice: Undefined index: global__r in /wp-content/db.php on line 507 PHP Notice: Trying to access array offset on value of type null in /wp-content/db.php on line 507 PHP Notice: Undefined index: global__r in /wp-content/db.php on line 510 PHP Notice: Undefined index: global__r in /wp-content/db.php on line 519

When defining the get_lag and get_lag_cache functions with the threshold, I get the above error.

`function get_lag_cache($wpdb) { try { // Create a new Redis instance $redis = new Redis(); $redis->connect('127.0.0.1', 6379); // Adjust host and port as needed

    $lag_data = $redis->get($wpdb->lag_cache_key);

    if ($lag_data === false || !isset($lag_data['timestamp']) || !isset($lag_data['lag'])) {
        return false;
    }

    if ($wpdb->lag_cache_ttl < time() - $lag_data['timestamp']) {
        return false;
    }

    return $lag_data['lag'];
} catch (Exception $e) {
    return false;
}

}

function get_lag($wpdb) { // Query to get the replication lag $results = $wpdb->get_results("SHOW SLAVE STATUS", ARRAY_A); if (isset($results[0]['Seconds_Behind_Master'])) { error_log($results[0]['Seconds_Behind_Master']); return $results[0]['Seconds_Behind_Master']; } else { return false; } }`

@dd32 Can you please help with this issue? I am not able to enable a lag monitor because of these warnings.

sanchit-hwd avatar Aug 11 '23 13:08 sanchit-hwd

Same issue here.

archon810 avatar Mar 19 '25 14:03 archon810