给typecho博客添加网站加载时间

想及时了解自己的typecho博客访问速度,简单的代码就可以实现!
typecho
在typecho博客主题文件
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;
}

然后在你需要显示时间的地方调用即可,一般在网站底部footer.php中引用:

<?php echo timer_stop();?>

就是这么简单,快点去自己的 typecho博客出实践吧!

互联网卡免费申请上线啦! 来领一张手机卡吧!☛☛☛点我免费领卡☚☚☚
Last modification:October 13th, 2019 at 11:01 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment

5 comments

  1. 烟尘

  2. ahxx

    已拿走,谢谢博主

  3. YAMADIE

    来串串门

  4. 梦魂

    来逛逛 嘿嘿

  5. mua

    不错