Skip to content

Commit 495f4f7

Browse files
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
1 parent d373e6e commit 495f4f7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/wp-admin/includes/class-wp-debug-data.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,21 @@ static function debug_data() {
925925
'private' => true,
926926
);
927927

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' ),
941+
);
942+
928943
// List must use plugins if there are any.
929944
$mu_plugins = get_mu_plugins();
930945

@@ -1444,6 +1459,29 @@ static function debug_data() {
14441459
return $info;
14451460
}
14461461

1462+
/**
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+
14471485
/**
14481486
* Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
14491487
*

0 commit comments

Comments
 (0)