【问题标题】:Server wont serve pages whenever uploading and parsing data Laravel每当上传和解析数据时,服务器都不会提供页面 Laravel
【发布时间】:2021-01-18 09:55:07
【问题描述】:

我一直在为我的系统开发生物特征解析模块我已经实现了将原始数据从生物特征单元读取到数据库中的目标。我的问题是,每当我系统中的用户上传原始生物特征文件时,服务器在处理上传和读取时不会提供任何页面或请求。我想有一些指点,并学习一些更好地处理这个过程的原则

来自单位的生物特征文件如下所示

  129   2019-06-23 18:13:10 1   0   0   0
   98   2019-06-23 18:51:46 1   0   0   0
  101   2019-06-23 19:07:29 1   1   0   0
  103   2019-06-23 19:07:37 1   1   0   0
   85   2019-06-23 21:14:01 1   1   0   0
  132   2019-06-23 23:48:54 1   1   0   0
  203   2019-06-24 03:45:44 1   0   0   0
  138   2019-06-24 04:10:06 1   0   0   0
  204   2019-06-24 05:12:57 1   0   0   0
  157   2019-06-24 05:58:07 1   0   0   0

该文件有 1,700 多行,每行是一个生物特征记录

在我的控制器中有这个来评估每一行并将其存储在数据库中 声明了一个生物特征批次,以跟踪正在上传的生物特征数据

public function store(Request $request)
{
    if(Auth::check()){
        $repeatedRecords =0;
        // evaluate if the file is recieved
        set_time_limit(360);
        if($request->hasFile('BiometricDataFile')){
            $biometricDataLogFile = file($request->BiometricDataFile);
            foreach($biometricDataLogFile as $logFile){
                $BiometricDBRecord = new Biometric;
                $biometricRecord = explode("\t", $logFile);
                $BiometricDBRecord->employee_id = $biometricRecord[0];
                $BiometricDBRecord->location = $request->location;
                $BiometricDBRecord->logDate = Carbon::parse($biometricRecord[1]);
                $date = explode(' ', $biometricRecord[1]);
                $BiometricDBRecord->bioDate = $date[0];
                $BiometricDBRecord->bioTime = $date[1];
                $BiometricDBRecord->uploaded_by = Auth::user()->employee_id;
                if(Biometric::where('logDate','=', $biometricRecord[1])->count() <= 0){
                    $BiometricDBRecord->save();
                }else{
                    $repeatedRecords++;
                }
               
            }

            $newBatch = new BiometricBatch();
            //Setting up data for return to view
            $timeNow = Carbon::now('GMT+8')->toDateTimeString();
            $thirtyMinEarlier = Carbon::now('GMT+8')->subHours(12)->toDateTimeString();
            $biometricDataSaved = Biometric::whereBetween('created_at', [$thirtyMinEarlier, $timeNow])->where('uploaded_by', Auth::user()->employee_id)->get();
            $biometricDataSaved->sortBy('logDate');
            $sortedFirst = $biometricDataSaved->first();
            $sortedLast = $biometricDataSaved->last();
            $newBatch->employee_id = Auth::user()->employee->id;
            $newBatch->batch_upload_date = Carbon::now();
            $newBatch->batch_start_date = $sortedFirst->logDate;
            $newBatch->batch_end_date = $sortedLast->logDate;
            $newBatch->isProcessed = false;
            $newBatch->save();
        }else{ //if the file is not recieved
            return "<h1> File not found </h1>";
        }
            $activityLog = new ActivityLog();
            $activityLog->employee_id = Auth::user()->employee_id;
            $activityLog->action = 'Has uploaded biometric data';
            $activityLog->save();
        
        return view('pages.employeeBiometric')->with('savedLogs', $biometricDataSaved, 'duplicates', $repeatedRecords);
    }else{
        return view('errors.401');
    }
       
}

我有一种直觉,我可能应该在 javascript 或 ajax 中执行此操作,但不知道从哪里开始以及如何执行。我想学习如何更好地实现它并从我的错误中学习,谢谢你有一个很棒的天。

【问题讨论】:

    标签: php laravel laravel-5 eloquent


    【解决方案1】:

    也许对于一些耗时太长的任务来说使用队列https://laravel.com/docs/8.x/queues很有用

    并去掉所有需要花费大量时间来工作文件的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-16
      • 2023-03-29
      • 2017-01-11
      • 2019-05-29
      • 2019-12-26
      • 1970-01-01
      • 2011-02-04
      • 2017-10-30
      相关资源
      最近更新 更多