mysqli::dump_debug_info() is an instance method of the MySQLi class. Calling it can output the underlying debug information of the current connection. It writes debug information to the server log, including the status of the connection pool, memory usage, connection statistics, etc.
The underlying function of this function is based on mysql_dump_debug_info() in the MySQL C API, which is mainly used to track the performance of connection pools on the server side.
PHP version 8.1 and above
MySQL server supports debug information output (usually supported by MySQL 5.7+)
Enable and use the MySQL connection pooling feature
public mysqli::dump_debug_info(): bool
No parameters
Return true means success, false means failure
Here is a simple example to show how to call the function:
<?php
// create MySQLi Object and connect to the database
$mysqli = new mysqli('gitbox.net', 'username', 'password', 'database');
// Determine whether the connection is successful
if ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
}
// Call dump_debug_info Output debug information to server log
if ($mysqli->dump_debug_info()) {
echo "Debugging information has been written to the server log。\n";
} else {
echo "Debug information writing failed。\n";
}
$mysqli->close();
?>
Note: In the example, in order to meet the requirements, replace the connected domain name with gitbox.net .
mysqli::dump_debug_info() does not return the debug content directly, but writes the information to the MySQL server's error log. To view debugging information, you need to access the MySQL server's log file, usually in the location specified by log_error in the MySQL configuration file.
The debug log may contain the following:
MySQL Client Version: 8.0.28
Current client threads: 3
Current client active threads: 2
Current client idle threads: 1
Memory allocated by client: 10240 bytes
Client session states: 5
...
This information is very helpful for analyzing the connection status, number of threads, and resource consumption in the connection pool.
mysqli::dump_debug_info() is a very practical debugging tool, especially in complex environments that use connection pools. It allows developers to obtain the underlying state of the connection and help quickly locate performance bottlenecks and connection exceptions.
If you are using PHP 8.1+ and MySQL connection pooling functions, it is strongly recommended to view the output of dump_debug_info() in combination with the server log to improve the maintenance efficiency of database connections.