0

我正在运行一个脚本,它决定了我的执行时间。当它计算时间时我得到一个负数。我希望它在执行时能给我带来积极的影响。

<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
echo "executed";

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
$minutes = (int)($totaltime/60)-$hours*60;
echo "This page was created in ".$minutes." minute/s";

?>
4

1 回答 1

5

microtime()字符串形式返回。尝试传入 true 以使其返回浮点值。这也会将您的代码缩短为:

$starttime = microtime(true);
echo "Executed";

$endtime = microtime(true);
$totaltime = $endtime - $starttime;
$minutes = intval(ceil(($endtime - $starttime) / 60));
echo "This page was created in " . $minutes . " minute(s)";
...

资源:http ://www.php.net/microtime

于 2013-03-07T14:18:57.167 回答