Ya Basha
Ya Basha

Reputation: 1952

Importing large excel file using laravel application

I managed to build a project similar to the video: "Import CSV in Laravel 5.5 + Matching Fields"

Using excel import instead of CSV, it works fine with small excel files (less than 1000 rows) but I have excel files with more than 13000 rows the app keeps issuing the following error:

Maximum execution time of 30 seconds exceeded
Level
ERROR
Exception
{
    "class": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
    "message": "Maximum execution time of 30 seconds exceeded",
    "code": 1,
    .
    .
    .

I tried different ways and I read Laravel Excel documentation > Import Section > Chunk Reading and Queued reading but this also didn't work as I import excel file to collection then match the fields and then create new models and save them.

Please, advice for any tip can help me to import large excel files and match database fields with excel file column headings.

Upvotes: 2

Views: 3073

Answers (2)

Ya Basha
Ya Basha

Reputation: 1952

Some times I receive 504 Gateway Time-out and sometimes I get laravel error:

Maximum execution time of 30 seconds exceeded or the value I set in max_execution_time as suggested by @Vaibhavi Sojitra

With these errors, it may be any of the following PHP parameters in the php.ini that is causing the PHP process to end abruptly, thus causing Nginx to get a "reset" from its peer (in this case, the php-fpm backend).

I couldn't come to a better laravel technique to solve this issue, the solution that worked for me (till I find a better one):

increase the following parameters in php.ini

max_input_time = ...
max_execution_time = ...
default_socket_timeout = ...

After that the import process worked well.

Upvotes: 0

Vaibhavi S.
Vaibhavi S.

Reputation: 1093

Change You PHP Configuration. Increase time by below 4 Ways.

  1. Increase the execution time at php.ini level,

    max_execution_time=300
    
  2. Use PHP at runtime to increase it,

    ini_set('max_execution_time',300);  //300 seconds = 5 minutes
    
  3. Use inside the .htaccess to increase it,

    php_value max_execution_time 300
    
  4. set time limit in __construct method or you can set in your index controller also where you want to have large time limit.

    public function __construct() { set_time_limit(500000); }

Upvotes: 1

Related Questions