ajitdas's avatar

Laravel Crash when Uploading Large Files

My Laravel application is crashing when I attempt to upload big CSV files. I am using Laravel 5.6, php 7.2, and Apache server. This error is in a local dev environment

My php.ini settings are like this

post_max_size=10000M
upload_max_filesize=10000M
memory_limit = -1

My code to upload the file is this

public function upload(Request $request){
        set_time_limit(0);
        ini_set('MAX_EXECUTION_TIME', 36000);
        $file = Input::file('file');
        $filePath = $file->getRealPath();

       $handle = fopen($filePath, "r");
        while(!feof($handle))
        {
           << DO THE DATABASE OPERATION >>
        }
        fclose($handle);

  return redirect()->back()->with('success', 'File uploaded successfully');
}

This code works fine for smaller file size such as 20mb( this has about 8 to 10k rows) , but when file size is big then that like 30mb( this has about 15 to 20k rows) or 40mb its gives that error after uploading 3 to 4k rows

Screenshot of error: https://i.stack.imgur.com/oqGY8.png

Any suggestion ??

0 likes
1 reply

Please or to participate in this conversation.