lundi 5 juin 2017

Timout when importing an excel file into database

I'm trying to import excel files to my MySQL database on Laravel 5.4 with the PHPExcel-based Maatwebsite/laravel-excel library.

The files I need to import are pretty big: at least 50k rows with 100 columns, and I need to create a database entry for each row.

I thought I may have some problems with the import process, so I started out with using chunks, however even at 1 chunks I get the following error message:

Maximum execution time of 180 seconds exceeded.

I tried to increase the max_execution_time variable and memory limit, but I still can't seem to go through with the import.

This is the code I'm using:

Excel::filter('chunk')->load($request->file('source_file')->getRealPath())->chunk(1,function ($results) {
    foreach($results as $row) {
        TaskMeta::create([
         'task_id' => $row['task_id'],
         'col2' => $row['column2'],
         ... etc, rest of the 100 columns ommited for clarity
        ]);
    }
});

I'm testing this locally in my Homestead environment by the way. I need a solution that would work on a production server as well.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire