feat: 同步下新环境
This commit is contained in:
@@ -11,8 +11,11 @@
|
||||
|
||||
namespace think\debug;
|
||||
|
||||
use think\Container;
|
||||
use think\Cache;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use think\Debug;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
|
||||
/**
|
||||
@@ -21,26 +24,27 @@ use think\Response;
|
||||
class Html
|
||||
{
|
||||
protected $config = [
|
||||
'file' => '',
|
||||
'tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'],
|
||||
'trace_file' => '',
|
||||
'trace_tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'],
|
||||
];
|
||||
|
||||
// 实例化并传入参数
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
$this->config['trace_file'] = THINK_PATH . 'tpl/page_trace.tpl';
|
||||
$this->config = array_merge($this->config, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试输出接口
|
||||
* @access public
|
||||
* @param Response $response Response对象
|
||||
* @param array $log 日志信息
|
||||
* @param Response $response Response对象
|
||||
* @param array $log 日志信息
|
||||
* @return bool
|
||||
*/
|
||||
public function output(Response $response, array $log = [])
|
||||
{
|
||||
$request = Container::get('request');
|
||||
$request = Request::instance();
|
||||
$contentType = $response->getHeader('Content-Type');
|
||||
$accept = $request->header('accept');
|
||||
if (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
|
||||
@@ -49,13 +53,13 @@ class Html
|
||||
return false;
|
||||
}
|
||||
// 获取基本信息
|
||||
$runtime = number_format(microtime(true) - Container::get('app')->getBeginTime(), 10, '.', '');
|
||||
$runtime = number_format(microtime(true) - THINK_START_TIME, 10, '.', '');
|
||||
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
|
||||
$mem = number_format((memory_get_usage() - Container::get('app')->getBeginMem()) / 1024, 2);
|
||||
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
|
||||
|
||||
// 页面Trace信息
|
||||
if ($request->host()) {
|
||||
$uri = $request->protocol() . ' ' . $request->method() . ' : ' . $request->url(true);
|
||||
if (isset($_SERVER['HTTP_HOST'])) {
|
||||
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
} else {
|
||||
$uri = 'cmd:' . implode(' ', $_SERVER['argv']);
|
||||
}
|
||||
@@ -63,18 +67,19 @@ class Html
|
||||
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $uri,
|
||||
'运行时间' => number_format($runtime, 6) . 's [ 吞吐率:' . $reqs . 'req/s ] 内存消耗:' . $mem . 'kb 文件加载:' . count(get_included_files()),
|
||||
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
|
||||
'缓存信息' => Container::get('cache')->getReadTimes() . ' reads,' . Container::get('cache')->getWriteTimes() . ' writes',
|
||||
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
|
||||
'配置加载' => count(Config::get()),
|
||||
];
|
||||
|
||||
if (session_id()) {
|
||||
$base['会话信息'] = 'SESSION_ID=' . session_id();
|
||||
}
|
||||
|
||||
$info = Container::get('debug')->getFile(true);
|
||||
$info = Debug::getFile(true);
|
||||
|
||||
// 页面Trace信息
|
||||
$trace = [];
|
||||
foreach ($this->config['tabs'] as $name => $title) {
|
||||
foreach ($this->config['trace_tabs'] as $name => $title) {
|
||||
$name = strtolower($name);
|
||||
switch ($name) {
|
||||
case 'base': // 基本信息
|
||||
@@ -99,7 +104,7 @@ class Html
|
||||
}
|
||||
// 调用Trace页面模板
|
||||
ob_start();
|
||||
include $this->config['file'];
|
||||
include $this->config['trace_file'];
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user