Make WordPress Core

Changeset 51522


Ignore:
Timestamp:
08/01/2021 02:00:17 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r51143 r51522  
    924924                        'value'   => $wpdb->collate,
    925925                        'private' => true,
     926                );
     927
     928                $info['wp-database']['fields']['max_allowed_packet'] = array(
     929                        'label' => __( 'Max allowed packet size' ),
     930                        'value' => self::get_mysql_var( 'max_allowed_packet' ),
     931                );
     932
     933                $info['wp-database']['fields']['max_connections'] = array(
     934                        'label' => __( 'Max connections number' ),
     935                        'value' => self::get_mysql_var( 'max_connections' ),
     936                );
     937
     938                $info['wp-database']['fields']['query_cache_size'] = array(
     939                        'label' => __( 'Query cache size' ),
     940                        'value' => self::get_mysql_var( 'query_cache_size' ),
    926941                );
    927942
     
    14461461
    14471462        /**
     1463         * Returns the value of a MySQL variable.
     1464         *
     1465         * @since 5.9.0
     1466         *
     1467         * @param string $var Name of the MySQL variable.
     1468         * @return string|null The variable value on success. Null if the variable does not exist.
     1469         */
     1470        public static function get_mysql_var( $var ) {
     1471                global $wpdb;
     1472
     1473                $result = $wpdb->get_row(
     1474                        $wpdb->prepare( 'SHOW VARIABLES LIKE %s', $var ),
     1475                        ARRAY_A
     1476                );
     1477
     1478                if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) {
     1479                        return $result['Value'];
     1480                }
     1481
     1482                return null;
     1483        }
     1484
     1485        /**
    14481486         * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
    14491487         *
Note: See TracChangeset for help on using the changeset viewer.