有时我们想要知道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日