XHanch Studio Log in | Register | Cart

Forum

[Free Script] PHP S...
 
Notifications
Clear all

[Free Script] PHP Script to show/display a complete list of MySQL processes

2 Posts
1 Users
0 Likes
1,628 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

This PHP Script is a tool to monitor your MySQL service/server and is used to show/display a complete list of MySQL processes with some details.

With this, we can see what is MySQL currently doing/executing. Provided information are active process ID, host name, users, databases being accessed, command type, state, running time per process, and SQL queries being executed.

Preview

Source code

Here is the complete code of this script

<?php
    //By    : Xhanch Studio
    //URL  : http://xhanch.com/

    if(!isset($_GET['xhc-token']))
        die('Invalid token');

    $db_usr = "mysql user";
    $db_pwd = "mysql password";
    $db_hst = "localhost";

    $ato_rfr = 0;

    if($ato_rfr > 0)
      echo '<meta http-equiv="refresh" content="'.$ato_rfr.'">';   

    $con = mysql_connect($db_hst, $db_usr, $db_pwd);
    $rcd = mysql_list_processes($con);

    echo '
        <style>
            body{
                background:#cacaca;
                padding:0;
                margin:0
            }

            table{
                border:1px solid #c0c0c0
            }

            td, th{
              font-family: arial;
              font-size: 12px;
              text-align:left
            }

            th{
                background:#000;
                color:#fff;
            }

            td{
                background:#ffffff;
                border-bottom:1px solid #000
            }

            .kld td{
              background:#ff0000;
              color:#fff
            }
        </style>

        <table cellpadding="3" cellspacing="0" border="0" width="100%">
            <thead>
                <th style="width:50px">ID</th>
                <th style="width:100px">Host</th>
                <th style="width:75px">User</th>
                <th style="width:100px">Database</th>
                <th style="width:100px">Command</th>
                <th style="width:75px">State</th>
                <th style="width:50px">Time</th>
                <th>Info</th>
            </thead>
    ';

    while ($row = mysql_fetch_assoc($rcd)){
      if($row['Time'] > 100)
          $cls = " class='kld'";
      else
          $cls = "";
     
      echo '
          <tr'.$cls.'>
              <td>'.($row['Id']?$row['Id']:'&nbsp;').'</td>
              <td>'.($row['Host']?$row['Host']:'&nbsp;').'</td>
              <td>'.($row['User']?$row['User']:'&nbsp;').'</td>
              <td>'.($row['db']?$row['db']:'&nbsp;').'</td>
              <td>'.($row['Command']?$row['Command']:'&nbsp;').'</td>
              <td>'.($row['State']?$row['State']:'&nbsp;').'</td>
              <td>'.($row['Time']?$row['Time']:'&nbsp;').'</td>
              <td>'.($row['Info']?$row['Info']:'&nbsp;').'</td>
          </tr>
      ';
    }

    echo '</table>';
?>
 
Posted : 02/08/2012 10:21 am
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

Invalid token

Add ?xhc-token to your script URL.
You can change this token to protect this page.

 
Posted : 29/04/2013 4:14 pm
Share:

× Close Menu