Skip to content

fix: Function mysqli_ping() is deprecated since 8.4 and no longer tries to reconnect since PHP 8.2#165

Open
macbre wants to merge 9 commits intotrunkfrom
fix/deprecated-mysqli-ping
Open

fix: Function mysqli_ping() is deprecated since 8.4 and no longer tries to reconnect since PHP 8.2#165
macbre wants to merge 9 commits intotrunkfrom
fix/deprecated-mysqli-ping

Conversation

@macbre
Copy link
Copy Markdown
Member

@macbre macbre commented Aug 6, 2025

This PR resolves Deprecated: Function mysqli_ping() is deprecated since 8.4 warnings.

The change has been checked internally and works fine - the lost connection is detected, the re-connection takes place and the query is sent properly.

Resources

@macbre macbre requested review from ArSn, aidvu, myhro, sjinks and vnsavage August 6, 2025 14:21
@macbre macbre self-assigned this Aug 6, 2025
@macbre macbre requested a review from rinatkhaziev August 6, 2025 18:30
@vnsavage
Copy link
Copy Markdown
Contributor

vnsavage commented Aug 6, 2025

This proposed change doesn't really implement everything that mysqli_ping() does, which we rely upon - Pings a server connection, or tries to reconnect if the connection has gone down - the reconnect, specifically.

Co-authored-by: Andrija Vučinić <andrija.vucinic@gmail.com>
@macbre macbre changed the title fix: Function mysqli_ping() is deprecated since 8.4 fix: Function mysqli_ping() is deprecated since 8.4 and no longer tries to reconnect since PHP 8.2 Aug 12, 2025
@macbre
Copy link
Copy Markdown
Member Author

macbre commented Aug 12, 2025

Interesting, ex_mysql_error() also has four return statements, but SonarCube complains:

This method has 4 returns, which is more than the 3 allowed.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

@aidvu
Copy link
Copy Markdown

aidvu commented Nov 19, 2025

Iliya had a good observation. If we get HYPERDB_SERVER_GONE_ERROR, we shouldn't try to ping, but go straight to disconnect():

HyperDB/db.php

Lines 1402 to 1407 in 2b329ab

// 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;
}

And I think with that, and some testing it's good to go.

Disconnect from database on server gone error.
Comment on lines 1404 to +1406
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;
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.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants