CakePHP 1.3:测量页面执行时间 [英] CakePHP 1.3: Measuring Page Execution Time
问题描述
试图弄清楚如何测量CakePHP网站的PHP总执行时间。看起来在1.2中,在调试模式下,它已作为HTML注释包含在呈现的HTML中,但这在我的1.3站点上没有发生,并且无论如何我都希望将其作为元素可以输出给用户,而不是
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.
我可以在常规PHP中使用microtime()轻松地做到这一点,但是我不确定在CakePHP中的代码添加位置,我怀疑它可能有一个无论如何,更强大的执行计时器。
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?
推荐答案
以防万一其他人好奇,我通过在我的layout.ctp中添加以下代码来解决此问题。您也可以在控制器中执行此操作,然后将其作为变量传递,这可能对MVC更为经典,但是我希望在网站的每个页面上都这样做,而不必在每个控制器中复制代码。
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.
这篇关于CakePHP 1.3:测量页面执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!