这个程序的目的是可以看到程序中执行查询的语句、次数和执行时间
希望各位插件作者能把自己的插件优化好,写出更好的插件
第一步
打开include/common.inc.php文件,找到
?>
在上面添加
$mtime = explode(' ', microtime());
$common_run =number_format(($mtime[1] + $mtime[0] - $discuz_starttime), 6);
$common_query =$db->querynum;
$starttime = $mtime[1] + $mtime[0];
第二步
打开include/global.func.php,找到
if($GLOBALS['debug']) {
global $db, $discuz_starttime, $debuginfo;
$mtime = explode(' ', microtime());
$debuginfo = array('time' => number_format(($mtime[1] + $mtime[0] - $discuz_starttime), 6), 'queries' => $db->querynum);
return TRUE;
} else {
return FALSE;
}
替换成
if($GLOBALS['debug']) {
global $db, $starttime, $common_run, $common_query, $gzipcompress;
$mtime = explode(' ', microtime());
$script_time = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
$script_query = $db->querynum - $common_query;
$toal_run = $common_run+$script_time;
echo "<br><b>Init</b>: ".$common_run.", ".$common_query ."queries. <b>Script</b>: ".$script_time." , ".$script_query." queries . <b>Total:</B>".$toal_run.",$db->querynum queries <br>".
($gzipcompress ? ' Gzip enabled' : NULL);
}
第三步
打开include/db_mysql.class.php,找到
function query($sql, $type = '') {
$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ?
'mysql_unbuffered_query' : 'mysql_query';
if(!($query = $func($sql)) && $type != 'SILENT') {
$this->halt('MySQL Query Error', $sql);
}
$this->querynum++;
return $query;
}
替换为
function query($sql, $type = '') {
$mtime = explode(' ', microtime());
$stime = $mtime[1] + $mtime[0];
$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ?
'mysql_unbuffered_query' : 'mysql_query';
if(!($query = $func($sql)) && $type != 'SILENT') {
$this->halt('MySQL Query Error', $sql);
}
$this->querynum++;
//tiger
$mtime = explode(' ', microtime());
$endtime =number_format(($mtime[1] + $mtime[0] - $stime), 6);
$this->queryinfo .="<hr>".$this->querynum.".) <font color=red>(cost: $endtime)</font>".dhtmlspecialchars($sql);
//tiger
return $query;
}
最后一步打开footer.htm模板,找到
</body></html>
在上面添加
<table cellspacing="0" cellpadding="0" border="0" width="97%" align="center">
<tr><td bgcolor="{BORDERCOLOR}">
<table border="0" cellspacing="{BORDERWIDTH}" cellpadding="{TABLESPACE}" width="100%" style="table-layout: fixed">
<tr bgcolor="#CCFFCC"><td align="center">This Script Queries Information</td></tr>
<tr bgcolor="{ALTBG1}">
<td align="left" width="100%">
{eval echo"$db->queryinfo";}
</td></tr></table>
</td></tr></table>
<BR><BR>
完成,这个以前2.5的时候是老师写的,最近升级到4.0我把那个移植过来了,希望对插件作者有帮助
我来到康盛之后学会一句话:功能仅仅实现是不够的!