Laravel-Excel massive import

ぃ、小莉子 提交于 2019-12-23 20:19:29

问题


So, I have an excel file with 28k rows.
I want to load it, then insert into database, but it was just stopped. (blank space)
I've tried to reduce into 5k data, and it worked, but is too slow
I also tried using chunk, with only 5k data, but I got "Maximum execution time of 300 seconds exceeded".
here's the code

Excel::filter('chunk')->load(storage_path('excel/exports/').$fileName)->chunk(1000, function($results)
    {
        foreach($results as $key)
        {
            // even nothing to do
        }
    });

Is 5k row really that big to handle?
Or am I doing it wrong?
Thanks.


回答1:


You're doing it by the book. (Using chuck, for example)
But 28k rows is much data to handle.

You can edit your maximum execution time.
see: http://php.net/manual/en/function.set-time-limit.php

bool set_time_limit ( int $seconds )

Hope this will help.




回答2:


Using chunk is great to prevent over exhausting memory but it will slow down your execution time.

Increase the number of chunk if you want it faster but be careful with that.

Note. Every end of chunk, your application gonna read the file again and that take time.



来源:https://stackoverflow.com/questions/30121055/laravel-excel-massive-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!