一个获取PHP消耗时间的小函数

<?php
header('Content-type:textml;charset=utf8;');

$startime = get_nowtime();

for ($i = 0; $i < 5; $i++) {
    sleep(1);
}

echo '模块A:'.get_exectime()."s<br/>";


for ($i = 0; $i < 3; $i++) {
    sleep(1);
}

echo '模块B:'.get_exectime()."s<br/>";

for ($i = 0; $i < 2; $i++) {
    sleep(3);
}

echo '模块C:'.get_exectime()."s<br/>";


function get_exectime() {
    global $startime;
    $nowtime = get_nowtime();
    $res = sprintf('%6f', $nowtime - $startime);
    $startime = $nowtime;
    return $res;
}

function get_nowtime() {
    list($mtime[0], $mtime[1]) = explode(' ', microtime());
    return sprintf('%6f',$mtime[0] + $mtime[1]);
}
原文地址:https://www.cnblogs.com/zflinux21/p/2728322.html