phpcms v9的debug函数

function usedtime(){ $stime = explode(' ', SYS_START_TIME); $etime = explode(' ', microtime()); return number_format(($etime[1] + $etime[0] - $stime[1] - $stime[0]), 6); } function debug(){ if(!pc_base::load_config('system','debug') || defined('HTML')) return false; $myip = array('答允显示debug信息的ip地点'); pc_base::load_sys_class('db_factory', '', 0); $sql_status = db_factory::get_instance(); $mysqlserver = pc_base::load_config('database');//漫衍式sql $count = $querystr = array(); foreach($mysqlserver AS $k=>$v){ $db_list = $sql_status->get_database($k); $count[] = $k.':'. $db_list->querycount; $querystr[] = $k.':'. implode(';<br />',$db_list->querystr); } $count = implode(';',$count); $querystr = implode(';',$querystr); $output = '<table><tr><td>执行时间</td><td>'.usedtime().'</td></tr><tr><td>sql执行轮廓</td><td>'.$count.'</td></tr><tr><td>sql执队列表</td><td>'.$querystr.'</td></tr></table>'; return in_array(ip(),$myip) ? $output : ''; }

假如回收了大都据库处事器,可以统计到所有处事器的查询次数.

别的假如想把执行的sql都打印出来,需要特别修改 mysql.class.php

增加变量界说 public $querystr = array();

并修改如下要领: private function execute($sql) { if(!is_resource($this->link)) { $this->connect(); } $stime = explode(' ', microtime()); $this->lastqueryid = mysql_query($sql, $this->link) or $this->halt(mysql_error(), $sql); $etime = explode(' ', microtime()); $sec_time = number_format(($etime[1] + $etime[0] - $stime[1] - $stime[0]), 6); if(pc_base::load_config('system','debug')) $this->querystr[] = $sql.'('.$sec_time.')'; $this->querycount++; return $this->lastqueryid; }

eee

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/7743.html