给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:February 21st, 2019 at 11:16 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment

4 comments

  1. ahxx     Windows 10 /    FireFox

    已拿走,谢谢博主

  2. YAMADIE     Windows 7 /    Google Chrome

    来串串门

  3. 梦魂     Windows 7 /    Google Chrome

    来逛逛 嘿嘿

  4. mua     Android Oreo /    Google Chrome

    不错