Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Modernization: handle mysqli_ping() deprecation in wpdb::check_c…
…onnection(). The `mysqli_ping()` function is deprecated as of PHP 8.4, though, in reality, the function wasn't working according to spec anymore since PHP 8.2 when the `libmysql` driver was dropped in favour of `libmysqlnd`, which was already the default (and recommended) driver since PHP 5.4. The `mysqli_ping()` method was also not really correctly named as its functionality was to reconnect to the database, not just ping. The alternative is to "manually" ping the database by sending a `DO 1` query (the cheapest possible SQL query). Adding a PHP version based toggle was considered, but as mentioned above, the default driver has been `libmysqlnd` since PHP 5.4 and in that case, the function never worked anyway, so in reality `mysqli_ping()` was only really functional for the odd custom PHP compilation where `mysqli` was build against `libmysql` AND `reconnect` was not disabled. With this in mind, this change replaces the call to `mysqli_ping()` with the `DO 1` query completely. If that query succeeds, it concludes the database connection is still alive. This solution should be the most stable as it will work for both PHP 7.2 <= 8.1, independently of which driver `mysqli` was compiled with, as well as for PHP 8.2+. Note: It could also be considered to remove the function call to `mysqli_ping()` completely and rely on standard error handling in case the connection would have dropped, as after all, the fact that the connection existed at the moment the "ping" happened, is no guarantee that the connection will still exist when the next query is send.... this approach was not chosen so as WP has custom error handling and does not use the PHP native mysqli exceptions for this, which would make implementing this more awkward. Includes a test to verify that the connection check works when there is a valid connection (this was previously not covered by tests). Refs: * https://wiki.php.net/rfc/deprecations_php_8_4#mysqli_ping_and_mysqliping * php/php-src#11912 (comment) * https://stackoverflow.com/questions/2546868/cheapest-way-to-determine-if-a-mysql-connection-is-still-alive/2546922#2546922 * php/php-src#11945 * https://wiki.php.net/rfc/mysqli_support_for_libmysql * https://www.php.net/mysqli_ping Follow-up to [56475], [27250], [27075]. Props jrf, hellofromTonya. See #62061. git-svn-id: https://develop.svn.wordpress.org/trunk@59069 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information