给网站加上显示页面查询次数、加载时间和内存占用的代码

wordpress学习30字数 431阅读1分26秒阅读模式

给网站加上显示页面查询次数、加载时间和内存占用的代码,记录一下,在主题functions.php中加上以下代码,然后在模板的footer.php最面的</html>加上<?php if(function_exists('performance')) performance(true) ;?>调用一下就行了。然后每个页面底部就会有这样的信息了:

26 queries in 1.629 seconds, using 11.33MB memory

 

//显示页面查询次数、加载时间和内存占用
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} -->" ;
}

 
  • 本文由 asdfasd 发表于 2025-02-1312:58:26
  • 转载请务必保留本文链接:http://wp.fangfa.me/wordpress-study/%e7%bb%99%e7%bd%91%e7%ab%99%e5%8a%a0%e4%b8%8a%e6%98%be%e7%a4%ba%e9%a1%b5%e9%9d%a2%e6%9f%a5%e8%af%a2%e6%ac%a1%e6%95%b0%e3%80%81%e5%8a%a0%e8%bd%bd%e6%97%b6%e9%97%b4%e5%92%8c%e5%86%85%e5%ad%98%e5%8d%a0.html