Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(View): Fix cost time miss in render
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Mar 10, 2019
1 parent eb9c905 commit 9cd155b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/views/layout/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<p class="copyright">
<a href="/" target="_self"><?= app()->config->get('base.site_name') ?></a> 2019-2020 Powered by <a href="https://github.com/Rhilip/RidPT">RidPT</a>
</p>
<p class="create-info">[ Page created in <b>{{ cost_time|number_format(5) }}</b> sec with <b><?= count(app()->pdo->getExecuteData()) ?></b> db queries, <b><?= array_sum(app()->redis->getCalledData())?></b> calls of Redis ]</p>
<p class="create-info">[ Page created in <b><?= number_format(microtime(true) - app()->request->start_at, 6) ?></b> sec with <b><?= count(app()->pdo->getExecuteData()) ?></b> db queries, <b><?= array_sum(app()->redis->getCalledData())?></b> calls of Redis ]</p>
</div>
</div>
</footer>
Expand Down
6 changes: 3 additions & 3 deletions framework/Http/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,17 @@ public function end($content = '')
}

/**
* @return mixed
* @return \Swoole\Http\Server
*/
public function getServ()
{
return $this->_serv;
}

/**
* @param mixed $serv
* @param \Swoole\Http\Server $serv
*/
public function setServ($serv): void
public function setServ(\Swoole\Http\Server $serv): void
{
$this->_serv = $serv;
}
Expand Down
8 changes: 0 additions & 8 deletions framework/Http/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ class Controller extends BaseObject

protected $start_time;

public function onInitialize()
{
$this->start_time = microtime(true);
}

public function render($name, $data = [])
{
$data['cost_time'] = microtime(true) - $this->start_time;
if (env('APP_DEBUG'))
$data['css_tag'] = time();
return (new View())->render($name, $data);
}
}
3 changes: 3 additions & 0 deletions framework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ class Request extends BaseRequest
// 请求对象
protected $_requester;

public $start_at;

// 设置请求对象
public function setRequester($requester)
{
$this->_requester = $requester;
// 重置数据
$this->start_at = microtime(true);
$this->setRoute([]);
$this->_get = isset($requester->get) ? $requester->get : [];
$this->_post = isset($requester->post) ? $requester->post : [];
Expand Down

0 comments on commit 9cd155b

Please sign in to comment.