[wp-trac] [WordPress Trac] #62061: Prepare for PHP 8.4

WordPress Trac noreply at wordpress.org
Thu Sep 19 18:55:15 UTC 2024


#62061: Prepare for PHP 8.4
---------------------------------------------+-----------------------------
 Reporter:  jrf                              |       Owner:  (none)
     Type:  task (blessed)                   |      Status:  new
 Priority:  normal                           |   Milestone:  6.7
Component:  General                          |     Version:
 Severity:  normal                           |  Resolution:
 Keywords:  php-84 has-patch has-unit-tests  |     Focuses:  php-
                                             |  compatibility
---------------------------------------------+-----------------------------

Comment (by hellofromTonya):

 In [changeset:"59069" 59069]:
 {{{
 #!CommitTicketReference repository="" revision="59069"
 Code Modernization: handle mysqli_ping() deprecation in
 wpdb::check_connection().

 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
 * https://github.com/php/php-src/pull/11912#issuecomment-1671762583
 * 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.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62061#comment:31>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list