Wordpress显示内存占用、查询次数和加载时间的代码

4.18K 浏览技术资料
1

有时我们想要知道Wordp页面加载所用的时长,还有在测试中想要知道页面打开过程中所用的数据库次数,使用以下代码即可:

function performance( $visible = false ) {
 $stat = sprintf(  '%d queries in %.3f seconds, using %.2fMB memory',
  get_num_queries(),
  timer_stop( 0, 3 ),
  memory_get_peak_usage() / 1024 / 1024
 );
 echo $visible ? $stat : "<!-- {$stat} -->" ;
}
add_action( 'wp_footer', 'performance', 20 );

分享到:
Qi 编辑问题 2019年10月18日
添加评论
写下您的答案。

Login

Welcome! Login in to your account

Remember me Lost your password?

Don't have account. Register

Lost Password

Register