Skip to content
19 changes: 16 additions & 3 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,8 @@ public function should_mysql_ping() {
// MySQL server has gone away
if ( isset( $this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] ) &&
HYPERDB_SERVER_GONE_ERROR == $this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] ) {
unset( $this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] );
return true;
$this->disconnect( $this->dbhname );
return false;
Comment on lines 1404 to +1406
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidvu - like that?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I don't think that's enough. It needs to behave the same way as this block:

HyperDB/db.php

Lines 523 to 532 in 8a51769

if ( $this->should_mysql_ping() && ! $this->ex_mysql_ping( $this->dbhs[ $dbhname ] ) ) {
if ( isset( $conn['disconnect (ping failed)'] ) ) {
++$conn['disconnect (ping failed)'];
} else {
$conn['disconnect (ping failed)'] = 1;
}
$this->disconnect( $dbhname );
break;
}

So we either move the HYPERDB_SERVER_GONE_ERROR check there, or and disconnect/break for PHP < 8.0.0 or we rewrite the check a bit.

}

// More than 0.1 seconds of inactivity on that dbhname
Expand Down Expand Up @@ -1556,7 +1556,20 @@ public function ex_mysql_ping( $dbh ) {
return @mysql_ping( $dbh );
}

return @mysqli_ping( $dbh );
// Deprecated: Function mysqli_ping() is deprecated since 8.4
// The mysqli.reconnect php.ini setting had been ignored by the mysqlnd driver, and was removed as of PHP 8.2.0.
if ( version_compare( PHP_VERSION, '8.2.0', '<' ) ) {
return @mysqli_ping( $dbh );
}

$res = $this->ex_mysql_query( 'SELECT /* hyperdb::ex_mysql_ping */ 1', $dbh );
if ( is_object( $res ) && 1 === $res->num_rows ) {
// The "ping" query was enough, the database connection is still there.
return true;
}

// Let the hyperdb logic reconnect us.
Copy link
Copy Markdown

@aidvu aidvu Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still thinking about this... @vnsavage wanted the reconnect logic here VS letting hyperdb just do its thing.

The reconnect was removed and wasn't working since at least 8.2. Considering that the fallback was good enough, not sure what value is there in having the reconnect re-implemented. In theory, it would be a bit faster then going through all of the logic for finding a server to connect to.

return false;
}

public function ex_mysql_affected_rows( $dbh ) {
Expand Down