对于一个非常简单的分析,我使用microtime()这样:
$now = microtime();
for (...) {
// do something
echo microtime() - $now;
$now = microtime();
}
Run Code Online (Sandbox Code Playgroud)
现在,该echo线的输出似乎是完全随机的,也就是说,我预计波动,但我没想到负数会出现.
但是,典型结果包含〜1/3的负数.我在Solaris(PHP 5.0.x)和WinVista(PHP 5.2.3)上证实了这一点.
到底发生了什么事?我是否意外地发明了一台时间机器?
Ark*_*rkh 68
如果要对microtime返回的内容执行操作,则必须将"get as float"参数设置为true(默认为false).
http://www.php.net/manual/en/function.microtime.php
$now = microtime(true);
for (...) {
// do something
echo microtime(true) - $now;
$now = microtime(true);
}
Run Code Online (Sandbox Code Playgroud)