mysqli::stat()
(PHP 5, PHP 7)
获取当前系统状态信息
说明
面向对象风格
mysqli::stat(void): string
过程化风格
mysqli_stat(mysqli$link): string
mysqli_stat()函数返回一个表示系统状态信息的字符串,字符串中的内容和'mysqladmin status'命令的输出结果类似,包含以秒为单位的运行时间、运行中的线程数、问题数、重新加载数以及打开的表数量等信息。
参数
- $link
仅以过程化样式:由mysqli_connect()或mysqli_init()返回的链接标识。
返回值
成功则返回表示系统状态信息的字符串,失败则返回FALSE
。
范例
Example #1 mysqli::stat()例程
面向对象风格
<?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* 检查连接 */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } printf ("System status: %s\n", $mysqli->stat()); $mysqli->close(); ?>
过程化风格
<?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* 检查连接 */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } printf("System status: %s\n", mysqli_stat($link)); mysqli_close($link); ?>
以上例程会输出:
System status: Uptime: 272 Threads: 1 Questions: 5340 Slow queries: 0 Opens: 13 Flush tables: 1 Open tables: 0 Queries per second avg: 19.632 Memory in use: 8496K Max memory used: 8560K
参见
- mysqli_get_server_info() 返回MySQL服务器的版本号
Here is an explanation of the values that appear in connection->stat() returned string. It was taken from Ai Hua's April 29, 2006 answer on http://forums.mysql.com/read.php?12,86570,86570. Uptime--The number of seconds the MySQL server has been running. Threads--The number of active threads (clients). Questions--The number of questions (queries) from clients since the server was started. Slow queries--The number of queries that have taken more than long_query_time seconds. Opens--The number of tables the server has opened. Flush tables--The number of flush-*, refresh, and reload commands the server has executed. Open tables--The number of tables that currently are open. Queries per second avg--Questions divided by Uptime