CakePHP 1.3: Measuring Page Execution Time

2019-05-25 03:08发布

Looking to figure out how to measure the total PHP execution time of a CakePHP site. It looks like in 1.2 this was included in the rendered HTML as a HTML comment when in debug mode, but this is not happening on my 1.3 site, and in any case I want it as an element I can output to the user, not a comment.

I can do this easily in regular PHP using microtime() but I'm not sure where to add the code in CakePHP, and I suspect it might have a more robust execution timer anyway. Ideas?

3条回答
狗以群分
2楼-- · 2019-05-25 03:50

This may not be the "right" way to do it, but you can add the following PHP code back into app/webroot/index.php (at the very end). Then if you have debug on > 0, you'll get the old 1.2 functionality back.

if (Configure::read() > 0) {
    echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
}
查看更多
SAY GOODBYE
3楼-- · 2019-05-25 03:59

Use Debug Kit. Among other functionality, you can grab the total execution time via

DebugKitDebugger::requestTime()
查看更多
贪生不怕死
4楼-- · 2019-05-25 04:00

Just in case anyone else is curious, I solved this by adding the following code to my layout.ctp. You could also do this in the controller and pass it in as a variable, which might be a little more classic MVC-friendly, but I wanted this on every page of the site without duplicating code in each controller.

Page rendered in <?php echo round((getMicroTime() - $_SERVER['REQUEST_TIME']) * 1000) ?>ms.
查看更多
登录 后发表回答