Skip to content

[QUESTION] Reading huge excel file consumes too much memory. Caused by simplexml_load_string #2793

@vroad

Description

@vroad

Prerequisites

Versions

  • PHP version: 7.4.9
  • Laravel version: 7.9.2
  • Package version: 3.1.21

Description

Reading huge excel file (over 10MB) causes php process to be killed. The sheet causing the issue is over 75MB after uncompressing the file.

I tracked down the place causing the error, and found that simplexml_load_string consumes around 2GB of memory.
Is there a way to reduce memory usage?

https://github.com/PHPOffice/PhpSpreadsheet/blob/9683e5be189080a9c75298e00efb72be3f5c866a/src/PhpSpreadsheet/Reader/Xlsx.php#L621

This only occurs with XLSX files because other types of files does not use SimpleXML for reading.
Chunked reading does not help because the problems occurs before laravel excel starts reading rows.

The problem is happening inside PhpSpreadsheet library, and SimpleXML is not suited for reading huge file as it tries to load entire tree into memory.
PhpSpreadsheet does not probably support other types of XML parses which uses less memory, so there is nothing I can do as long as I use Laravel Excel?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions