WordPress 7.0 Beta 5 :即将进入 RC 阶段,新功能与稳定性全面升级
WordPress 7.0 开发进程迎来关键节点——最后一个 Beta ...
平常在维护WordPress的时候想要看看每个页面的加载时间、内存占用量等数据都很不方便,下面我们来说下如何使用WordPress显示数据库查询次数、内存占用及加载时间。
下面给大家整理的这种方法,种是通过代码直接生成的。
将一下代码添加到主题functions.php文件的最后面
仅管理员可见
add_action( 'wp_footer', function () {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$stat = sprintf( '本页生成数据库 %d 次查询,耗时 %.3f 秒,使用 %.2fMB 内存',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo "<center>{$stat}</center>";
} );
任何人可见
add_action( 'wp_footer', function () {
$stat = sprintf( '本页生成数据库 %d 次查询,耗时 %.3f 秒,使用 %.2fMB 内存',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo "<center>{$stat}</center>";
} );
评论交流(0)