PHP 8.3.4 Released!

mysql_stat

(PHP 4 >= 4.3.0, PHP 5)

mysql_statObtiene el estado actual del sistema

Advertencia

Esta extensión fue declarada obsoleta en PHP 5.5.0 y eliminada en PHP 7.0.0. En su lugar debería utilzarse las extensiones MySQLi o PDO_MySQL. Véase también la guía MySQL: elegir una API. Las alternativas a esta función son:

Descripción

mysql_stat(resource $link_identifier = NULL): string

mysql_stat() devuelve el estado actual del servidor.

Parámetros

link_identifier

La conexión MySQL. Si no se especifica el identificador de enlace, se asume el último enlace abierto por mysql_connect(). Si no se encuentra este enlace, se intentará crear un nuevo enlace como si mysql_connect() hubiese sido invocada sin argumentos. Si no se encuentra o establece ninguna conexión, se genera un error de nivel E_WARNING.

Valores devueltos

Devuelve un string con el estado del tiempo de funcionamiento, hilos, consultas, tablas abiertas, tablas de volcado y consultas por segundo. Para obtener una lista completa de variables de estado, es necesario usar el comando SQL SHOW STATUS. Si link_identifier no es válido, se devuelve null.

Ejemplos

Ejemplo #1 Ejemplo de mysql_stat()

<?php
$enlace
= mysql_connect('localhost', 'usuario_mysql', 'contraseña_mysql');
$estado = explode(' ', mysql_stat($enlace));
print_r($estado);
?>

El resultado del ejemplo sería algo similar a:

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
)

Ejemplo #2 Ejemplo alternativo de mysql_stat()

<?php
$enlace
= mysql_connect('localhost', 'usuario_mysql', 'contraseña_mysql');
$resultado = mysql_query('SHOW STATUS', $enlace);
while (
$fila = mysql_fetch_assoc($resultado)) {
echo
$fila['Nombre_variable'] . ' = ' . $fila['Valor'] . "\n";
}
?>

El resultado del ejemplo sería algo similar a:

back_log = 50
basedir = /usr/local/
bdb_cache_size = 8388600
bdb_log_buffer_size = 32768
bdb_home = /var/db/mysql/
bdb_max_lock = 10000
bdb_logdir =
bdb_shared_data = OFF
bdb_tmpdir = /var/tmp/
...

Ver también

add a note

User Contributed Notes 3 notes

up
3
billbilljr at gmail dot com
13 years ago
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
up
0
Enzo_01 at abv dot bg
15 years ago
<?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 ) )
*/

?>
up
-1
Anonymous
19 years ago
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;
}
?>
To Top