用于ThinkPHP6+的页面Trace扩展,支持Html页面和浏览器控制台两种方式输出。
composer require topthink/think-trace
安装后config目录下会自带trace.php配置文件。
type参数用于指定trace类型,支持html和console两种方式。
debug trace bar for thinkphp6
License: Apache License 2.0
public function handle($request, Closure $next)
{
$debug = $this->app->isDebug();
// 注册日志监听
if ($debug) {
$this->log = [];
$this->app->event->listen(LogWrite::class, function ($event) {
if (empty($this->config['channel']) || $this->config['channel'] == $event->channel) {
$this->log = array_merge_recursive($this->log, $event->log);
}
});
}
$response = $next($request);
// Trace调试注入
if ($debug) { //这里的判断,还是读取的最初的值,无法在其他中间件或控制器中,改变此属性
$data = $response->getContent();
$this->traceDebug($response, $data);
$response->content($data);
}
return $response;
}
Html的写法是
// 获取基本信息
$runtime = number_format(microtime(true) - $app->getBeginTime(), 10, '.', '');
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
$mem = number_format((memory_get_usage() - $app->getBeginMem()) / 1024, 2);
在Console里面却是
// 获取基本信息
$runtime = number_format(microtime(true) - $app->getBeginTime(), 10);
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
$mem = number_format((memory_get_usage() - $app->getBeginMem()) / 1024, 2);
在Console里,当$runtime大于1000会出现千位分割,1/$runtime会出现“A non well formed numeric value encountered”错误
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.