I'm having memory problems writing several XLSX files with 500 columns and 200 rows. It seems PHPExcel is not releasing memory. After two files with memory_limit = 128M I get a white screen. Writing just one file succeeds. Tested with both PHPExcel 1.7.9. and 1.8.0.
Here are some numbers. This is what I use:
drupal_set_message('<pre>'. sprintf("%9s", memory_get_usage()) . ' - pre phpexcel</pre>');
$result = phpexcel_export($headers, $data, $path, $options);
drupal_set_message('<pre>'. sprintf("%9s", memory_get_usage()) . ' - post phpexcel</pre>');
This results in:
20871016 - pre phpexcel
74431992 - post phpexcel
($data is about 15MB).
If I add some extra messages in phpexcel.inc I get this:
20871016 - pre phpexcel
20871832 - :start phpexcel_export
21683144 - :object created
79609648 - :columns set
79717632 - :writer created
74452000 - :end phpexcel_export
74431992 - post phpexcel
Looping through three files with memory_limit = 256M gives:
3241880 - indicator 106 resource found
21125888 - set data
21127336 - pre phpexcel
74537120 - post phpexcel
58790928 - unset data
58782832 - indicator 106 file created
58818528 - indicator 295 resource found
71658616 - set data
71659520 - pre phpexcel
115556344 - post phpexcel
102724992 - unset data
102716792 - indicator 295 file created
102761176 - indicator 262 resource found
128664744 - set data
128665672 - pre phpexcel
198014592 - post phpexcel
172095512 - unset data
172087304 - indicator 262 file created
What's going on? Am I doing something wrong? Is this due to an error in the module or the library, or just normal behavior? Could I manually free some memory?
Comments
Comment #1
wadmiraal commentedWow, I'm really sorry it took me one year to get back at you for this.
Do you have any further info on this ? Did you solve it ? I would definitely think it's the library, as the module is just a wrapper around it to provide a more friendly and Drupal-like API.
Comment #2
gaele commentedI was not able to solve this, so I used a work-around (a batch call per file, and enough memory). It seems like a problem with the library indeed.
Comment #3
gaele commentedComment #4
wadmiraal commentedHave you checked the memory settings at admin/config/system/phpexcel ? You can now choose how PHPExcel (the library) caches the data. This can have an impact.
(I need to update the documentation... my bad).
Comment #5
wadmiraal commentedUpdated the documentation.
Comment #6
gaele commentedI tried several cache settings, without noticing any difference.
Comment #7
wadmiraal commentedCan you try applying the following patch and see if it works? I simply unset the writer (and the reader, in the import function). I know PHP sometimes does not unset variables and the end of a function execution.
Comment #8
gaele commentedHi, thanks for the patch. I'm currently away from the office. Will be back second half of March, and test your patch then.
Comment #9
wadmiraal commentedAny news on this? Did you have the opportunity to try it out?
If it works, I will include it in the next release.
Comment #10
gaele commentedNot yet. I will test tomorrow and let you know.
Comment #11
gaele commentedSorry, I don't notice any difference in memory use.
As I said in #2 I coded around the problem, so just close this issue if you wish.
Comment #12
wadmiraal commentedWell, then I don't know. It probably is related to the library. Sorry about that, but good to know you found a way around it.