gpt4 book ai didi

使用 microtime() : Negative time? 进行 PHP 分析

转载 作者:IT王子 更新时间:2023-10-29 00:54:55 25 4
gpt4 key购买 nike

对于一个非常简单的分析,我使用 microtime() 像这样:

$now = microtime();
for (...) {
// do something
echo microtime() - $now;
$now = microtime();
}

现在,echo 行的输出看起来完全是随机的,也就是说,我预期会有波动,但我没有预期负数 出现。

但是,典型结果包含 ~ 1/3 负数。我在 Solaris (PHP 5.0.x) 和 WinVista (PHP 5.2.3) 上确认了这一点。

这到底是怎么回事?我是不是不小心发明了一台时光机?

最佳答案

如果要对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);
}

关于使用 microtime() : Negative time? 进行 PHP 分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com