前言
闲来无事给网站加了个响应时间耗时代码,下面是以本站为列的代码教程
将以下代码存放到主题的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;
  }
  **最后再在你想要它出现的地方加上以下代码**

?php echo timer_stop();
最后修改:2022 年 01 月 13 日 10 : 49 PM
如果觉得我的文章对你有用,请随意赞赏