人性化格式的页面生成时间

时间:2016-09-07 09:47:43

标签: php

function PageStartTime() {
        $time = microtime();
        $time = explode(' ', $time);
        $time = $time[1] + $time[0];
        $start = $time;
    }

function pageFinishTime() {
        $time = microtime();
        $time = explode(' ', $time);
        $time = $time[1] + $time[0];
        $finish = $time;
        $total_time = round(($finish - $start), 1);
        echo "Page generated in $total_time seconds.";
        echo 'Peak memory usage: ',round(memory_get_peak_usage()/1048576, 2), 'MB';
    }

打印:

  

页面生成于1473241297.4秒。内存使用量:0.56MB

如何更改"human-friendly"格式?

1 个答案:

答案 0 :(得分:1)

我不确定你是否在上课,但如果没有,你必须参考$ start时间;

private $start = 0;

function PageStartTime() {
    $this->start = microtime(true);
}

function pageFinishTime() {
        $finish = microtime(true);
        $total_time = round(($finish - $this->start), 4);
        echo "Page generated in $total_time seconds.";
        echo 'Peak memory usage: ',round(memory_get_peak_usage()/1048576, 2), 'MB';
    }