How to fix memory getting exhausted with PHPExcel?

前端 未结 8 452
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 04:43

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1078799 bytes) in D:\\xampplite\\htdocs\\Scraper\\PHPExcel\\Reader\\Exc

相关标签:
8条回答
  • 2020-11-28 05:11

    Just because the data file is only X bytes, doesn't mean it uses X bytes of ram. For example only 4K of data in a $_SESSION array uses 64K of ram when loaded up. It just depends what the code is doing with that data. The correct answer is to increase the amount of ram.

    Also if this is a XLSX file, they are ZIP'd XML documents. Text files zip up far tighter than 1/2, so your 350K XLSX file is easily a 1MB Excel file.

    0 讨论(0)
  • 2020-11-28 05:13

    Xdebug is profiler/debugger for php and can help you trace through memory usage and functional calls to figure out where the problem lies. And its easy to install, most linux distributions have it in repository, "yum install xdebug", "apt-get install xdebug".

    0 讨论(0)
  • 2020-11-28 05:14

    If you want to find out, you can use xhprof. According to this link, you can trace memory usage with it...

    0 讨论(0)
  • 2020-11-28 05:18

    PHPExcel is known for memory leaks. I advise you to use the following which need a FRACTION of the memory that PHPExcel uses.:

    1) For Reading: PHP-Excel-Reader

    2) For Writing: Pear Spreadsheet Excel Writer

    0 讨论(0)
  • 2020-11-28 05:18
    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load("test.xlsx");
    

    This much code is enough

    0 讨论(0)
  • 2020-11-28 05:22

    This post talks about how to close a PHPExcel reader: How to close excel file in php-excel-reader If you're opening multiple Excel files simultaneously, but actually not need them all at the same time, then you could try to open and close(i.e. unset) the readers for each file one by one. Btw, using the same variable name for readers would suffice for the "unsetting" operation.

    0 讨论(0)
提交回复
热议问题