PHP Doku:: Zeigt den momentanen Serverstatus an - function.mysql-stat.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenMySQLMySQL Funktionenmysql_stat

Ein Service von Reinhard Neidl - Webprogrammierung.

MySQL Funktionen

<<mysql_set_charset

mysql_tablename>>

mysql_stat

(PHP 4 >= 4.3.0, PHP 5)

mysql_statZeigt den momentanen Serverstatus an

Beschreibung

string mysql_stat ([ resource $Verbindungs-Kennung ] )

mysql_stat() liefert den momentanen Serverstatus zurück.

Hinweis:

mysql_stat() liefert nur die Werte uptime, threads, queries, open tables, flush tables und queries pro sec. Für eine komplette Liste der anderen Statusvariablen sollte der SQL-Befehl SHOW STATUS verwendet werden.

Beispiel #1 mysql_stat() Beispiel

<?php
$link 
mysql_connect('localhost'"mysql_user""mysql_password");
$status explode('  'mysql_stat($link));
print_r($status);
?>

Das oben gezeigte Beispiel liefert die folgende Ausgabe:

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
)

Siehe auch mysql_get_server_info() und mysql_list_processes().


4 BenutzerBeiträge:
- Beiträge aktualisieren...
billbilljr at gmail dot com
6.01.2011 20:46
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
Topper_
2.09.2008 22:51
<?php

    $mysql_stat
=mysql_stat($dbconnect);
   
   
$tot_count=preg_match_all('/([a-z ]+):\s*([0-9.]+)/i', $mysql_stat, $matches);

    for (
$i=0; $i<$tot_count; $i++) {
       
$info1=$matches[1][$i];
       
$info2=$matches[2][$i];
       
        echo
"$info1 ($info2)<br>";
    }

/*
example output:

Uptime (13651)
Threads (1)
Questions (12910)
Slow queries (0)
Opens (314)
Flush tables (1)
Open tables (24)
Queries per second avg (0.945)

*/

?>
Enzo_01 at abv dot bg
31.05.2008 21:22
<?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);
}
/*
example return:
Array ( [0] => Uptime: 385815 [1] => Threads: 1 [2] => Questions: 3515 [3] => Slow queries: 0 [4] => Opens: 32 [5] => Flush tables: 1 [6] => Open tables: 8 [7] => Queries per second avg: 0.009 [Uptime] => Array ( [0] => Uptime [1] => 385815 ) [Threads] => Array ( [0] => Threads [1] => 1 ) [Questions] => Array ( [0] => Questions [1] => 3515 ) [Slow queries] => Array ( [0] => Slow queries [1] => 0 ) [Opens] => Array ( [0] => Opens [1] => 32 ) [Flush tables] => Array ( [0] => Flush tables [1] => 1 ) [Open tables] => Array ( [0] => Open tables [1] => 8 ) [Queries per second avg] => Array ( [0] => Queries per second avg [1] => 0.009 ) )
*/

?>

9.02.2005 3:16
if you need the complete status as outputted by the "show status" command. Try this function.
<?
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;
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)