在特定日期和时间保存数据时出错

Error when saving data on a specific date and time

我有一台装有 Debian 10、Apache/2.4.38、MySQLi、mongodb 和 Php 的服务器。服务器是 运行 一个自定义 PHP 程序,允许用户上传他们的测量结果(在 .csv 文件中),然后存储在 mongodb.

上传的.csv文件必须符合预定格式才能上传,例如:

Timestamp,Measurement 1,Measurement 2,(etc)
05/06/20 00:15,201,1
05/06/20 00:30,305,4
05/06/20 00:45,400,65
.
.
(continues for the entire duration of the day/week/year)

时间戳必须准确地每 15 分钟设置一次。负责此检查的代码是:

//check time interval
if (isset($document['timestamp']) && $time_step==false && $fileLine>1){
    if ($interval>900){
        $time_step=true;
        $condition_violated=True;
        $conditions_errors.="line ".$fileLine. " warning: The ".$key[$i]." condition is violated. \r\n";
        file_put_contents($file_name,"line ".$fileLine. " error: One or more time instants are missing in the file you try to upload. Please check the consistency of the measurements in the file. \r\n",FILE_APPEND);
    }
}

除每年一个非常具体的日期和时间外,这工作正常。 尝试上传从 2019 年 2 月 22 日 00:15 开始到 2019 年 12 月 31 日 23:45 结束的文件时,出现错误:

line 23724 error: One or more time instants are missing in the file you try to upload. Please check the consistency of the measurements in the file. 

上面一行是日期:27/10/19 02:45 如果我将文件拆分为两个不同的 .csv 文件,第一个包含第 1-23723 行,第二个包含第 23725 行,基本上跳过第 23724 行 - 日期 27/10/19 02:45,该文件上传就好了。

如果我尝试仅使用以下三个时间步长上传文件:

Timestamp,Measurement 1,Measurement 2,(etc)
27/10/19 02:30,0,0
27/10/19 02:45,0,0
27/10/19 03:00,0,0

我得到了同样的错误。 整个 2020 年的 25/10/20 02:45 出现了同样的问题。 尝试了很多 .csv 文件,同样的错误。

我正在尝试了解 OS、PHP 代码或数据库 (mongodb) 是否有问题。 有什么建议吗?

第一次编辑

@Buzz 检查间隔的代码应该在这里:

for($i=0; $i < $numofcols; $i++){
    $key[$i] =remove_utf8_bom($key[$i]) ;
    $min_max_violated=False;
    if ($key[$i] == "Timestamp"){
        if(strlen($value[$i]) != 14){
            $date_time_error=true;
            $dt=0;
            file_put_contents($file_name,"line ".$fileLine. " error: Date-Time format error.\r\n",FILE_APPEND);
        }else{
            $document['timestamp'] = $value[$i];
            if ($fileLine == 1){
            $timestamp_to_cmp=DateTime::createFromFormat('d/m/y H:i',$document['timestamp'])->getTimestamp();
            $dt=$timestamp_to_cmp;
            }
            else{
                $dt = DateTime::createFromFormat('d/m/y H:i',$document['timestamp'])->getTimestamp();
                $interval=$dt-$timestamp_to_cmp;
/*                  echo json_encode(["dd"=>$interval]);
                exit(); */
            }
        }

Mongodb 出现在不同的 .php 文件中,我认为错误出在这个文件中。

日期 27/10/19 02:45 是时间更改发生的日期。 在那一刻 PHP 增加了 +3600 秒的测量。 显然,这只发生在 debian 安装上,它在 Arch linux 上没有改变就可以工作。 我通过添加修复它:

date_default_timezone_set('UTC');

在文件的开头 PHP 检查时间间隔。