Reading multiple files with PHPExcel

I just recently started using this library (the one from CodePlex), but I ran into some problems. My goal is to use it so that I can process some data from several Excel files and send such data to the database for each file. I am doing something like:

foreach( $file_list as $file ) { $book = PHPExcel_IOFactory::load( $path . $file ); } 

So, inside the foreach, I (for now) just show the data to the user, but after five files I get a memory error:

 Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 50688 bytes) in /var/www/test/classes/PHPExcel/Shared/OLERead.php on line 76 

Is there a way to __destruct the object after downloading each file, so the space is reserved (done for free) for the next file, instead of accumulating it, or do you rather know the reason and workaround for this?

Please let me know any suggestions you have.

Thanks in advance.

+4
source share
2 answers

The latest SVN code for PHPExcel (just installed today) is caching cells to reduce memory usage ... it's such a new feature, I didn't even have time to document it. Although the default method is identical to the existing method, with a worksheet relation โ†” containing a circular reference, I believe that using any of the caching mechanisms that reduce memory should eliminate this circular reference. If not, let me know and I can break the link when you turn off the workbook / sheet using some caching logic that already disconnects this connection when serializing cells for caching.

+2
source

This has been a problem for a while, and it doesn't seem like a way around this - that is, unless someone has come up with something clever since release 5.3 ......

"... it looks like PHP 5.3 will fix this. However, I would like to see confirmation of this somewhere." [10.21.2008]

( source ) ( more material )

0
source

Source: https://habr.com/ru/post/1307803/


All Articles