©
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
(PHP 4 >= 4.3.0, PHP 5)
mysql_stat — 取得当前系统状态
$link_identifier
] )mysql_stat() 返回当前服务器状态。
Note:
mysql_stat() 目前只返回 uptime,threads,queries,open tables,flush tables 和 queries per second。要得到其它状态变量的完整列表,只能使用 SQL 命令 SHOW STATUS。
Example #1 mysql_stat() 例子
<?php
$link = mysql_connect ( 'localhost' , "mysql_user" , "mysql_password" );
$status = explode ( ' ' , mysql_stat ( $link ));
print_r ( $status );
?>
以上例子将产生如下输出:
Array ( [0] => Uptime: 5380 [1] => Threads: 2 [2] => Questions: 1321299 [3] => Slow queries: 0 [4] => Opens: 26 [5] => Flush tables: 1 [6] => Open tables: 17 [7] => Queries per second avg: 245.595 )
[#1] billbilljr at gmail dot com [2011-01-06 11:46:27]
The following script can be used to clearly print out the results of mysql_stat().
<?php
mysql_connect("localhost", "username", "password");
$array = explode(" ", mysql_stat());
foreach ($array as $value){
echo $value . "<br />";
}
?>
Outputs something similar to:
Uptime: 698
Threads: 1
Questions: 4
Slow queries: 0
Opens: 19
Flush tables: 1
Open tables: 12
Queries per second avg: 0.5
[#2] Enzo_01 at abv dot bg [2008-05-31 12:22:16]
<?php
// function that return stat elements into array
function mysql_stat_array($A=null) {
$status = explode(' ', mysql_stat());
foreach($status as $k=>$v) { $v=explode(':',$v,2); $status[$v[0]]=$v[1]; }
return (isset($status[$A])?$status[$A]:$status);
}
?>
[#3] [2005-02-08 18:16:41]
if you need the complete status as outputted by the "show status" command. Try this function.
<?php
function mysql_status($db=NULL) {
if(!mysql_ping($db))
$db=mysql_connect("localhost","user","password");
$res=mysql_query("show status",$db);
while (list($key,$value)=mysql_fetch_array($res))
$sql[$key]=$value;
return $sql;
}
?>