09 Sql Query Counter

Started by Mindless, July 22, 2012, 12:33:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#1
@file include/bittorrent.php right under first :

Code (php) Select
<?php

Add this :

Code (php) Select
//==Start execution time
$q['start'] = microtime(true);


Add the function near the bottom i would say :

Code (php) Select
//==Sql query count
function sql_query($query) {
    global $queries, $q, $querytime, $query_stat;
    $queries++;
    $query_start_time  = microtime(true); // Start time
    $result            = mysql_query($query);
    $query_end_time    = microtime(true); // End time
    $query_time        = ($query_end_time - $query_start_time);
    $querytime = $querytime + $query_time;
    $q['querytime']    = (isset($q['querytime']) ? $q['querytime'] : 0) + $query_time;
    $query_time        = substr($query_time, 0, 8);
    $q['query_stat'][] = array('seconds' => $query_time, 'query' => $query);
    return $result;
    }


In function stdhead global line add these :

Code (php) Select
, $querytime, $query_stat, $q

function stdfoot global line add these :

Code (php) Select
$querytime, $q, $queries, $query_stat,
 
Right under the global line add this - Note debug code is commented out and you add your userid into the array to use it, remember to remove the old htmlfoot html :

   
Code (php) Select
$queries = (!empty($queries) ? $queries : 0);
    $q['debug']       = array(1); // Add staff USER IDs
    $q['seconds']     = (microtime(true) - $q['start']);
    $q['howmany']     = ($queries != 1 ? 's ' : ' ');
    $q['serverkillers'] = $queries > 6 ? '<br />'.($queries/2).' Server killers ran to show you this page :) ! =[' : '=]';
    $htmlfoot = "<p align='center'>
    <span class='server'>The {$TBDEV['site_name']}
    Server killers generated this page in ".(round($q['seconds'], 4))." seconds and then took a nap.<br />
    They had to raid the server ".$queries." time'".$q['howmany']." ".$q['serverkillers']."</span></p>";
    /*
    if (SQL_DEBUG && in_array($CURUSER['id'], $q['debug'])) {
    if ($q['query_stat']) {
    $htmlfoot .= "<br />
  <div class='roundedCorners' style=\"text-align:left;width:80%;border:1px solid black;padding:5px;\">
    <div style=\"background:#890537;height:25px;\"><span style=\"font-weight:bold;font-size:12pt;\">Querys</span></div>
  <table width=\"100%\" align=\"center\" cellspacing=\"5\" cellpadding=\"5\" border=\"0\">
<tr>
<td class=\"colhead\" width=\"5%\"  align=\"center\">ID</td>
<td class=\"colhead\" width=\"10%\" align=\"center\">Query Time</td>
<td class=\"colhead\" width=\"85%\" align=\"left\">Query String</td>
</tr>";
    foreach ($q['query_stat'] as $key => $value) {
    $htmlfoot  .= "<tr>
<td align=\"center\">".($key + 1)."</td>
<td align=\"center\"><b>". ($value['seconds'] > 0.01 ?
"<font color=\"red\" title=\"You should optimize this query.\">".
    $value['seconds']."</font>" : "<font color=\"green\" title=\"Query good.\">".
  $value['seconds']."</font>")."</b></td>
<td align=\"left\">".htmlspecialchars($value['query'])."<br /></td>
</tr>";        
    }
    $htmlfoot .='</table></div><br />';
    }
    }
    */

   
Go to all pages except announce and change mysql_query to sql_query :)