我已經使用microtime()來檢查代碼的執行時間。 但似乎很奇怪,像跟蹤的時間不正確。PHP microtime()是否正確?
在我的test.php的所以,我有這樣的代碼如下:
$debug = true;
$start = microtime(true);
$newline = "<br/>";
...
if ($debug) {
$time_elapsed_secs = microtime(true) - $start;
$start = microtime(true);
echo 'Step 1 Done: ' . $time_elapsed_secs . $newline; }
...
if ($debug) {
$time_elapsed_secs = microtime(true) - $start;
$start = microtime(true);
echo 'Step 2 Done: ' . $time_elapsed_secs . $newline; }
後來,當我打開瀏覽器的URL,它在不到1秒, 反應,但它顯示了像 一些奇怪的值步驟1完成:0.0026565 步驟2完成:9.8646454
這是怎麼發生的? 我做錯了什麼嗎?
「完成第1步:0.0026565」 的意思,它採取0.0026565秒得到這一點。 「第2步完成:9.8646454」意味着它花費了9.8646454秒才能到達該點。 – samlev