响应结果:
Yii请求类实例化开始时间戳:109070854,结束时间戳:109070854,共计用时:0
核心组件、设置时区、设置框架路径、实例化开始时间戳:109070854,结束时间戳:109070855,共计用时:1
定义错误处理程序开始时间戳:109070855,结束时间戳:109070855,共计用时:0
初始化组件和拓展开始时间戳:109070855,结束时间戳:109070856,共计用时:1
实例化控制器开始时间戳:109070856,结束时间戳:109070928,共计用时:72
action运行开始时间戳:109070928,结束时间戳:109071014,共计用时:86
接口请求始时间戳:109070856,结束时间戳:109071014,共计用时:158
{"success":true,"result":{"code":200,"result":{"have_more":true,"list":[{"id":"KETQTNOV","article_id":"00KETQQ2Z5JXZZU3ED6KYYPK","author_id":"00K7PSUV4PEZJLXD9XI1TAJQ","summary":"TCP/IP入门经典 chapter6 传输层\n问题驱动TCP 协议是不限制一个特定的连接(两端 socke","is_auto_summary":2,"created_at":1599556807,"author":{"id":"00K7PSUV4PEZJLXD9XI1TAJQ","avatar":"0e09f4a6e1915e881363bf03e9459434.png","nickname":"南方小菜"}}],"code":2027}}}
接口请求始时间戳:结束时间戳:109071014
1.修改 项目根目录下 \vendor\yiisoft\yii2\base\Application.php __construct方法
public function __construct($config = [])
{
Yii::$app = $this;
$instanceStart = self::getMillisecond();
static::setInstance($this);
$instanceEnd = self::getMillisecond();
$instanceTotal = $componentEnd - $componentStart;
echo "Yii请求类实例化开始时间戳:{$instanceStart},结束时间戳:{$instanceEnd},共计用时:{$instanceTotal}\n";
$this->state = self::STATE_BEGIN;
$preInitStart = self::getMillisecond();
$this->preInit($config);
$preInitEnd = self::getMillisecond();
$preInitTotal = $preInitEnd - $preInitStart;
echo "核心组件、设置时区、设置框架路径、实例化开始时间戳:{$preInitStart},结束时间戳:{$preInitEnd},共计用时:{$preInitTotal}\n";
$registerErrorStart = self::getMillisecond();
$this->registerErrorHandler($config);
$registerErrorEnd = self::getMillisecond();
$registerErrorTotal = $registerErrorEnd - $registerErrorStart;
echo "定义错误处理程序开始时间戳:{$registerErrorStart},结束时间戳:{$registerErrorEnd},共计用时:{$registerErrorTotal}\n";
$componentStart = self::getMillisecond();
Component::__construct($config);
$componentEnd = self::getMillisecond();
$componenTotal = $componentEnd - $componentStart;
echo "初始化组件和拓展开始时间戳:{$componentStart},结束时间戳:{$componentEnd},共计用时:{$componenTotal}\n";
}
2.修改 项目根目录下 vendor\yiisoft\yii2\base\Module.php
public function runAction($route, $params = [])
{
$controllerStart = Application::getMillisecond();
$parts = $this->createController($route);
if (is_array($parts)) {
/* @var $controller Controller */
list($controller, $actionID) = $parts;
$oldController = Yii::$app->controller;
Yii::$app->controller = $controller;
$controllerEnd = Application::getMillisecond();
$controllerTotal = $controllerEnd - $controllerStart;
echo "实例化控制器开始时间戳:{$controllerStart},结束时间戳:{$controllerEnd},共计用时:{$controllerTotal}\n";
$actionStart = Application::getMillisecond();
$result = $controller->runAction($actionID, $params);
$actionEnd = Application::getMillisecond();
$actionTotal = $actionEnd - $actionStart;
echo "action运行开始时间戳:{$actionStart},结束时间戳:{$actionEnd},共计用时:{$actionTotal}\n";
if ($oldController !== null) {
Yii::$app->controller = $oldController;
}
return $result;
}
$id = $this->getUniqueId();
throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
}
3.修改 项目根目录下 \vendor\yiisoft\yii2\base\Application.php run()方法
public function run()
{
try {
$this->state = self::STATE_BEFORE_REQUEST;
$this->trigger(self::EVENT_BEFORE_REQUEST);
$requestStart = self::getMillisecond();
$this->state = self::STATE_HANDLING_REQUEST;
$response = $this->handleRequest($this->getRequest());
$requestEnd = self::getMillisecond();
$requestTotal = $requestEnd - $requestStart;
echo "接口请求始时间戳:{$requestStart},结束时间戳:{$requestEnd},共计用时:{$requestTotal}\n";
$this->state = self::STATE_AFTER_REQUEST;
$this->trigger(self::EVENT_AFTER_REQUEST);
$this->state = self::STATE_SENDING_RESPONSE;
$response->send();
$responseEnd = self::getMillisecond();
echo "接口请求始时间戳:结束时间戳:{$responseEnd}\n";
$this->state = self::STATE_END;
return $response->exitStatus;
} catch (ExitException $e) {
$this->end($e->statusCode, isset($response) ? $response : null);
return $e->statusCode;
}
}