Typecho获取页面加载时间

在主题functions.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;
}

在主题合适位置引入

<?php _e('页面加载耗时'); ?><?php echo timer_stop();?>

浪子

Typecho代码,教程,Typecho模板,Typecho插件

0 条评论

暂无评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注