PHPSpreadSheet 20000 records

0

I recently worked with the PHPSpreadSheet library to read and create Excel files with a browser. The problem is this:

I have tried to create an Excel based on records of a table in SQL, the result of the query is approximately 20,000 records. So I throw a memory error, I tried to load the 5,000 records in 5,000 but it does not work.

It shows me the following error:

  

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 12582920 bytes) in C: \ xampp \ htdocs \ vPemex \ vendor \ phpoffice \ phpspreadsheet \ src \ PhpSpreadsheet \ Collection \ Cells.php on line 144

Any suggestions?

    
asked by Alejandro Flores 09.11.2018 в 16:45
source

2 answers

0

You can add the following to the beginning of your php file:

ini_set('memory_limit', '-1');

It is not a highly recommended solution, but it will allow more server memory to be used temporarily. PHP resource limit

    
answered by 09.11.2018 в 18:49
0

You must optimize your code to the maximum.

  • Reduce SQL requests.
  • Use PHP's own functions.
  • Delete unnecessary data.
  • Avoid bottlenecks.
  • Avoid copying variables.
  • ETC, ETC, ETC

In summary, check the number of nested loops you have. Also, do not implement more control structures than necessary .

To evaluate and compare the efficiency of several code fragments, the best (and almost only) option is to use a Benchmark. Check out this link

Another option is to increase the memory limit for that script.

ini_set('memory_limit', '2048M');
    
answered by 11.12.2018 в 13:12