NYCPHP Meetup

NYPHP.org

[nycphp-talk] how to find the mysql server status

Mark Armendariz lists at enobrev.com
Mon Jul 16 00:05:04 EDT 2007


On 7/15/07, Jon Baer <jonbaer at jonbaer.com> wrote:
>
> mysql_stat()
> http://us2.php.net/manual/en/function.mysql-stat.php

mysql_stat is good.  You can use a more direct status query if you
need more than that using "show status":
http://dev.mysql.com/doc/refman/5.1/en/show-status.html

<?php
	function dbg($var) {
		echo '<pre>' . print_r($var, 1) . '</pre>';
	}
	
	function get_mysql_full_status() {
		$aReturn = array();
		$oStatus = mysql_query('SHOW STATUS');
		while($aStatus = mysql_fetch_row($oStatus)) {
			$aReturn[$aStatus[0]] = $aStatus[1];
		}
		
		return $aReturn;
	}

	$oConnection = mysql_connect('localhost', 'me', 'y0 m at m@');
	
	dbg(mysql_stat());
	dbg(get_mysql_full_status());
?>

> However the fact that you want # of queries made in a single page might be
> better to just do a query log dump and view it.

If you're using a class or function for db access, you could increment
a static or global var  each time you run the mysql_query function and
then in a destructor or at the end of the page you have your query
count.



More information about the talk mailing list