侧边栏壁纸

Typecho添加网站加载时间

  • 老罗 原创作品 14天前
  • 默认分类 暂无标签~
  • 385阅读2评论1点赞
  • 直接在主题下的 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();?>` 
    1

    —— 评论区 ——

    昵称
    邮箱
    网址
    取消
    1. 头像
      胖氪笔记中国安徽省安庆市联通
      Windows 10   Google Chrome
      回复

      这个比较实用

      1. 头像
        老罗中国广东省汕尾市移动博主
        Windows 10   Microsoft Edge
        回复
        @胖氪笔记

        都是网上搬来的 ::twemoji:smile::

    我的音乐