From 2a0191b901e8d2c8e1e6b2fd824e1d7a5134a63b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 1 Aug 2021 14:02:00 +0000 Subject: [PATCH] Site Health: Add some more MySQL information to the Site Health Info screen. This adds three values to the debug info in the Database section: * Max allowed packet size * Max connections number * Query cache size Props zodiac1978, donmhico, mukesh27, SergeyBiryukov. Fixes #53845. Built from https://develop.svn.wordpress.org/trunk@51522 git-svn-id: http://core.svn.wordpress.org/trunk@51133 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-debug-data.php | 38 +++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/class-wp-debug-data.php b/wp-admin/includes/class-wp-debug-data.php index 016c9e3129..a044414789 100644 --- a/wp-admin/includes/class-wp-debug-data.php +++ b/wp-admin/includes/class-wp-debug-data.php @@ -925,6 +925,21 @@ class WP_Debug_Data { 'private' => true, ); + $info['wp-database']['fields']['max_allowed_packet'] = array( + 'label' => __( 'Max allowed packet size' ), + 'value' => self::get_mysql_var( 'max_allowed_packet' ), + ); + + $info['wp-database']['fields']['max_connections'] = array( + 'label' => __( 'Max connections number' ), + 'value' => self::get_mysql_var( 'max_connections' ), + ); + + $info['wp-database']['fields']['query_cache_size'] = array( + 'label' => __( 'Query cache size' ), + 'value' => self::get_mysql_var( 'query_cache_size' ), + ); + // List must use plugins if there are any. $mu_plugins = get_mu_plugins(); @@ -1444,6 +1459,29 @@ class WP_Debug_Data { return $info; } + /** + * Returns the value of a MySQL variable. + * + * @since 5.9.0 + * + * @param string $var Name of the MySQL variable. + * @return string|null The variable value on success. Null if the variable does not exist. + */ + public static function get_mysql_var( $var ) { + global $wpdb; + + $result = $wpdb->get_row( + $wpdb->prepare( 'SHOW VARIABLES LIKE %s', $var ), + ARRAY_A + ); + + if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) { + return $result['Value']; + } + + return null; + } + /** * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 20a041782c..24eccc05eb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51521'; +$wp_version = '5.9-alpha-51522'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.