Snippets v2

Languages
My Snippets

Mysql-status in XML Login or Register to Bookmark this snippet

Description PHP

This snippet, allows for statistics on mysql using the status function in the mysql client. For this script to work, it needs to have a mysql user names "status" which effectively has no permissions, and no access to any tables, therefore being very secure, and also unobtrusive. The xml formatting allows for several different types of translation and usage.

The Code Download
  1. <?php
  2. //this script gets the average queries per second
  3. $status = shell_exec('mysqladmin status -u status');
  4.  
  5. $status = str_replace(': ',':',$status);
  6. $status = str_replace(' Queries','  Queries',$status);
  7. //$status = str_replace(' ','',$status);
  8. $statusArray = explode('  ', $status);
  9. foreach($statusArray as $k => $v) {
  10.     $vArray = explode(':',$v);
  11.     $outputArray[str_replace(' ','',$vArray[0])] = round(($vArray[1]));
  12.     };
  13.  
  14. echo "<?xml version="1.0" encoding="ISO-8859-1" ?>n";
  15. echo "<mysqlStatus>n";
  16. foreach($outputArray as $k => $v) {
  17.     echo " <".$k.">".$v."</".$k.">n";
  18.     };
  19. echo "</mysqlStatus>n";
  20. ?>
Credits Contact JC

Added by JC on 12th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment