日志/图形PHP执行时间
时间:2020-03-06 14:43:56 来源:igfitidea点击:
有没有可用的工具来记录php网站的页面加载时间?
主要是寻找一些我可以看到加载时间随时间变化的趋势,我正在考虑使用error_log()将它们转储到文件中,但是我不知道该如何解析和显示图形
解决方案
将Firebug扩展程序用于Firefox,它具有一个" Net"面板,可显示加载时间。
如果要进行负载测试,则apache附带了一个名为apache bench的实用程序,请在我们附近的控制台窗口中尝试ab --help。
我们可以在执行开始时记录微时间,将变量保持到结束,检查时间,将其减去,即可获得执行时间。在大多数情况下,将需要输出缓冲来使此工作正常进行,除非在特定情况下总是要最后运行某个情况(例如" footer()")。
$time_start = microtime_float(); function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } //at the start. //at the end: $time_end = microtime_float(); $time = round($time_end - $time_start, 4); echo "Last uncached content render took $time seconds";
请参阅PEAR Benchmark。它允许我们将基准添加到代码中。我们可以让它在页面上转储HTML表,或者可以遍历数据并写入日志文件。