教你如何在页脚中添加查询次数、执行时间、内存占用

  • A+
了解查询次数、执行时间、内存占用,对于我们优化博客速度起到很关键的作用,今天就来说下如何在博客页脚中添加这些信息。

 首先需要改写主题的functions.php文件,在末尾处加入如下代码:

  1. //显示时间
  2. function performance( $visible = false ) {
  3.     $stat = sprintf(  '%d queries in %.3f seconds, using %.2fMB memory',
  4.         get_num_queries(),
  5.         timer_stop( 03 ),
  6.         memory_get_peak_usage() / 1024 / 1024
  7.     );
  8.     echo $visible ? $stat : "<!-- {$stat} -->" ;
  9. }
  10. //显示时间

 

接下来是如何在前端显示了,找到footer.php后,在</body>前添加如下的代码:

  1. <div id=huangxiansen><?php if(function_exists('performance')) performance(ture) ;?></div>

这时博客页脚即可显示相关信息,如果对出现的位置不太满意,希望可以居中,可以使用博客样式。

添加如下代码到style.css的末尾处:

  1. /** 时间样式 **/  
  2. #huangxiansen{margin:0px auto; 10px no-repeat #fff;huangxiansen:1px solid #D7D8DF;padding:10px;width:378px;}  
  3. /** 样式结束 **/  

 

黄 先森

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: