前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >网站添加加载时间

网站添加加载时间

作者头像
qiangzai
发布2021-12-20 21:09:27
1.1K0
发布2021-12-20 21:09:27
举报
文章被收录于专栏:强仔博客强仔博客

网页添加加载时间,适用于一切网站,放在合适的位置即可,今天就对于我的这个博客系统来讲来个简单教程。

代码食用

首页在主题下的 functions.php 中加入以下代码

代码语言:javascript
复制
/*
* 加载时间
* @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文件,根据你的实际情况)调用即可:

代码语言:javascript
复制
加载耗时:<?php echo timer_stop();?>

代码效果

我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=xp5d9fxk7lsq

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-061,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 代码食用
  • 代码效果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档