From 495f4f76414cbef9ce3c6cdcf942b2dfd691b11c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 1 Aug 2021 14:00:17 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@51522 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-debug-data.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 016c9e3129..a044414789 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/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. *