Phpoffice/phpspreadsheet returns "Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)"

I am using PHP office/PHP spreadsheet 1.0 extension for uploading excel, reading the data, and save into the database. But when deleted some rows from excel and tried to upload the file, it returns “Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)”.But the same is working before deleting the rows from excel . The issue shows only on excel version 2007-2019 format. The same is works for the excel format 2007-2013 format. How can I solve this issue in yii2?
I am using docker and my php version is 7.3

Memory must be freed by unset

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$spreadsheet = $reader->load($inputFileName);
unset($reader);

Implement caching:
https://phpspreadsheet.readthedocs.io/en/latest/topics/memory_saving/

Thank you for your reply. I tried the
unset($reader) method.But this does not work for me.

Unset all big objects and variables, if it do not use more.

Have you tried to increase the PHP memory_limit?

Since you are using docker, there is a good chance the container is low on memory.

Thank you…let me try

Thank you. Yes, I have already tried .But didn’t work

try to load your excel rows in chunks.

I solve the issue by using IOFactory::identify() method. It was an excel format issue.Thak you all for the support

1 Like