L
L
lolka022019-12-17 16:20:21
Yii
lolka02, 2019-12-17 16:20:21

Why is Yii2-excel using so much memory with xlsx files?

Uploading a file in xlsx format
$file = UploadedFile::getInstance($this, 'file');
$data = Excel::import($file->tempName);
The file weighs 1 mb the script runs for a very long time sometimes it gives an error about lack of memory I
upload in xls format everything works OK, why is it so, although the data in the files is the same

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2020-01-05
@lolka02

1. Refuse when working with Excel data in the form of objects - pass simple arrays. This will greatly reduce memory, especially if you are using AR.
2. Use queues and a console application. The console application has no memory or duration limits.

I
index0h, 2019-12-17
@index0h

xlsx is a zip archive with a bunch of stuff. The fact that the file is 1mb means literally nothing. To parse this file into components, you need quite a lot of memory. PHPOffice / PhpSpreadsheet is used internally, each cell of your document is an object, so count it))
If everything is critical for you from memory, you can look in the direction of converting xlsx -> csv (here we process everything you need) -> xlsx

A
Andrey, 2019-12-17
@reaferon

To read Excel, I recommend using a package (in the composer "phpoffice/phpspreadsheet")
In it, in pieces (for example, 500 lines), read the file, then there will be no problems with memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question