留方

给typecho博客添加网站加载时间
想及时了解自己的typecho博客访问速度,简单的代码就可以实现!在typecho博客主题文件functions....
扫描右侧二维码阅读全文
23
2019/02

给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

3 comments

  1.   Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 68.0.3423.2(Google Chrome 68.0.3423.2) YAMADIE

    来串串门

  2.   Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 72.0.3626.109(Google Chrome 72.0.3626.109) 梦魂

    来逛逛 嘿嘿

  3.   Android 8.0.0(Android 8.0.0) / Opera 4.0(Opera 4.0) mua

    不错