Faster write to database from excel Laravel 5 file

I am creating a module that you load into the database from an excel file. These are just phone numbers. So here is my code:

        $file = Input::file('file');
        Excel::load($file, function($reader) {
            // Getting all results
            $results = $reader->get()->toArray();
            //var_dump($results);exit;
            foreach ($results as $key => $value) {
                $phone = new Phone();
                $phone->msisdn          =  $value['msisdn'];
                $phone->save();
            }
        });

I am using https://github.com/Maatwebsite/Laravel-Excel to read the excel file. It works fine, 20,000 records load in 20 minutes, I think there is a way for it or load it faster? I know this also depends on the server, but are there other factors? I am using MySQL

thanks

+4
source share
2 answers

(https://github.com/rap2hpoutre/fast-excel):

(new FastExcel)->import($file, function ($line) {
    $phone = new Phone();
    $phone->msisdn = $value['msisdn'];
    $phone->save();
});
0

Source: https://habr.com/ru/post/1606430/


All Articles