先来两张截图看下效果
配置如下
Application\Common\Conf\tags.php
<?php return array( ‘app_end‘ => array( ‘Behavior\FireShowPageTrace‘ ) );
====================================================================================================================================
下面是详细流程
====================================================================================================================================
主要原来:利用firephp的类库
http://www.firephp.org/HQ/Install.htm
下载解压后如下图php5和php4的类库
根据配置文件
‘app_end‘ => array(‘Behavior\FireShowPageTrace‘)
ThinkPHP\Library\Think\App.class.php
会执行FireShowPageTraceBehavior类run方法
// 行为扩展的执行入口必须是run public function run(&$params){ if(C(‘FIRE_SHOW_PAGE_TRACE‘)){ $this->showTrace(); } }
我们现在看看这个文件ThinkPHP\Library\Behavior\FireShowPageTraceBehavior.class.php
把firephp的类库中的fb.php和FirePHP.class.php合并通过FireShowPageTraceBehavior类的showTrace方法调用显示信息
下面我们研究下showTrace方法
private function showTrace() { // 系统默认显示信息 $files = get_included_files(); $info = array(); foreach ($files as $key => $file) { $info[] = $file . ‘ ( ‘ . number_format(filesize($file) / 1024, 2) . ‘ KB )‘; } $trace = array(); $base = array( ‘请求信息‘ => date(‘Y-m-d H:i:s‘, $_SERVER[‘REQUEST_TIME‘]) . ‘ ‘ . $_SERVER[‘SERVER_PROTOCOL‘] . ‘ ‘ . $_SERVER[‘REQUEST_METHOD‘] . ‘ : ‘ . __SELF__, ‘运行时间‘ => $this->showTime(), ‘内存开销‘ => MEMORY_LIMIT_ON ? number_format((memory_get_usage() - $GLOBALS[‘_startUseMems‘]) / 1024, 2) . ‘ kb‘ : ‘不支持‘, ‘查询信息‘ => N(‘db_query‘) . ‘ queries ‘ . N(‘db_write‘) . ‘ writes ‘, ‘文件加载‘ => count(get_included_files()), ‘缓存信息‘ => N(‘cache_read‘) . ‘ gets ‘ . N(‘cache_write‘) . ‘ writes ‘, ‘配置加载‘ => count(c()), ‘会话信息‘ => ‘SESSION_ID=‘ . session_id(), ); // 读取应用定义的Trace文件 $traceFile = CONF_PATH . ‘trace.php‘; if (is_file($traceFile)) { $base = array_merge($base, include $traceFile); } $debug = trace(); $tabs = C(‘TRACE_PAGE_TABS‘); foreach ($tabs as $name => $title) { switch (strtoupper($name)) { case ‘BASE‘:// 基本信息 $trace[$title] = $base; break; case ‘FILE‘: // 文件信息 $trace[$title] = $info; break; default:// 调试信息 if (strpos($name, ‘|‘)) {// 多组信息 $array = explode(‘|‘, $name); $result = array(); foreach ($array as $name) { $result += isset($debug[$name]) ? $debug[$name] : array(); } $trace[$title] = $result; } else { $trace[$title] = isset($debug[$name]) ? $debug[$name] : ‘‘; } } } foreach ($trace as $key => $val) { if (!is_array($val) && empty($val)) { $val = array(); } if (is_array($val)) { $fire = array( array(‘‘, ‘‘) ); foreach ($val as $k => $v) { $fire[] = array($k, $v); } fb(array($key, $fire), FirePHP::TABLE); } else { fb($val, $key); } } unset($files, $info, $log, $base); }
组装数据
foreach ($tabs as $name => $title) {
会组装成
$tabs[基本]=$base;
$tabs[文件]=$info;
$tabs[流程]=$debug[INFO]
$tabs[SQL]=$debug[SQL]
$tabs[调试]=$debug[DEBUG]
$debug数据是根据Think\Think::trace获取的
$tabs[错误] 看下面代码可以看出
if (strpos($name, ‘|‘)) {// 多组信息 $array = explode(‘|‘, $name); $result = array(); foreach ($array as $name) { $result += isset($debug[$name]) ? $debug[$name] : array(); } $trace[$title] = $result; } else {
下面就是循环数组之后调用fb函数输出
foreach ($trace as $key => $val) {
fb(array($key, $fire), FirePHP::TABLE);
// 读取应用定义的Trace文件 $traceFile = CONF_PATH . ‘trace.php‘; if (is_file($traceFile)) { $base = array_merge($base, include $traceFile); }所以可以在Application\Common\Conf\trace.php写自己的扩展信息如下
Application\Common\Conf\trace.php
<?php return array( ‘COOKIE‘ => $_COOKIE, );
注:firePHP,是通过http headers和firebug通讯的,所以trace之前不能有输出 如
Application\Common\Conf\config.php 开启显示页面Trace信息
<?php return array( ‘SHOW_PAGE_TRACE‘ => TRUE, // 显示页面Trace信息 );
修改ThinkPHP\Library\Behavior\FireShowPageTraceBehavior.class.php
查找
return new Exception($Message);
改为
return new \Think\Exception($Message);
修正后你会看到如下图所示
原文:http://blog.csdn.net/starparker/article/details/18882725