
Typecho更新到1.2版本后,网上好多代码都不能用了,这个是1.2可用的页面加载时间代码。
在主题 functions.php 文件里放入下面代码
- /**
- * 加载时间
- * @return bool
- */
- function timer_start() {
- global $timestart;
- $mtime = explode( ' ', microtime() );
- $timestart = $mtime[1] + $mtime[0];
- return true;
- }
- timer_start();
- function timer_stop( $display = 0, $precision = 3 ) {
- global $timestart, $timeend;
- $mtime = explode( ' ', microtime() );
- $timeend = $mtime[1] + $mtime[0];
- $timetotal = number_format( $timeend - $timestart, $precision );
- $r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
- if ( $display ) {
- echo $r;
- }
- return $r;
- }
然后在主题foot.php文件需要放加载时间的地方添加
- 加载耗时:<?php echo timer_stop();?>
本文来自投稿,不代表本站立场,如若转载,请注明出处:
如果使用了pjax 那么回调函数应该怎么写.只有第一次刷新的页面才有时间,其他的页面ms会一直不动