网站显示网页加载时间代码-Typecho

忘心
2020-12-02 / 6 评论 / 2,506 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年05月16日,已超过871天没有更新,若内容或图片失效,请留言反馈。

前言

给你的网站加一个显示加载时间;
我也不知道咋想的,就是感觉加上会更好;

效果图

实际上你看到的会和本站有点差距,本站这是主题自带的,但功能都是一样的!

效果图

代码

代码放在主题文件

function.php

  /**
     * 加载时间
     */
    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挂载代码,也可以去post.php

代码

21

评论 (6)

取消
  1. 头像
    对对对
    Windows 10 · Google Chrome

    呵呵哈哈哈或

    回复
  2. 头像
    马化腾
    Android · Google Chrome

    画图

    回复
  3. 头像
    漫川
    Windows 10 · Google Chrome

    画图

    回复
  4. 头像
    七七
    Android · Google Chrome

    吞吞吐吐

    回复
  5. 头像
    766009194
    Android · Google Chrome

    不错表情

    回复
  6. 头像
    766009194
    Android · Google Chrome

    不错表情

    回复