非格式数值遇到错误


A non well formed numeric value encountered error

这段代码过去是在脚本运行大约15分钟时工作的,现在脚本需要更长的时间运行,所以我得到这个错误

PHP注意:第151行遇到一个格式不正确的数值

$time_start = microtime(true);
//Removed script
$time_end = microtime(true);
$time = $time_end - $time_start;
$time = number_format($time,0);
$time = gmdate("H:i:s",$time);   //LINE 151
$stmt = $mysqli->prepare("INSERT INTO updater(duration) VALUES(?)");
$stmt->bind_param('s', $time);
$stmt->execute();
$stmt->close();

"非格式数值"。您正在将STRING in传递给gmdate(),它需要一个整数时间戳。

你可能想要

$time = $time_end - $time_start
$formatted = gmdate('H:i:s', (int)$time);
...
$stmt->bind_param('s', $formatted);

。注意(int),因为您的时间开始/结束值是浮点值,而date/gmdate期望时间以秒为单位。PHP会为您转换,但我喜欢让它显式…