I have an app, that using maatwebsite/laravel-excel
lib, imports excel file with employees data. On each imported row app creates a new user. After that, it fetches all created users and sends to them an email with temp credentials.
Controller.php
public function import(Request $request) {
ini_set('max_execution_time', '0');
$import = new EmpImport();
try {
$import->import($request->file('file'));
}catch (\Maatwebsite\Excel\Validators\ValidationException $e){
return back()->withErrors('Error: '.$e->getMessage());
}
$users = User::whereDate('created_at',Carbon::today())->whereNotNull('temp_pass')->get();
$when = Carbon::now();
if (count($users) > 0){
foreach ($users as $user){
$emp = $user->emp;
$error = null;
if (!$emp->contact->exists() || $emp->contact->email == null)
continue;
try{
$error = Mail::to($emp->contact->email)->later($when->addSeconds(5), new AccountCreated($emp,$user->temp_password));
}catch (\Exception $e){
$error = $exception);
}
if ($error === null){
$user->temp_password = null;
$user->save();
}
}
}
ini_set('max_execution_time', '30');
return back();
}
It worked fine with 100 rows but when excel file became 1k+ Nginx started to give me 504 Gateway Timeout error
, so I changed its configurations to:
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
But on the next try, it showed 502 bad gateway
:(....