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?

CommentFileSizeAuthor
#7 phpexcel_free_up_memory-2269095-7.patch607 byteswadmiraal

Comments

wadmiraal’s picture

Status: Active » Postponed (maintainer needs more info)

Wow, 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.

gaele’s picture

I 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.

gaele’s picture

Status: Postponed (maintainer needs more info) » Active
wadmiraal’s picture

Status: Active » Postponed (maintainer needs more info)

Have 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).

wadmiraal’s picture

Updated the documentation.

gaele’s picture

I tried several cache settings, without noticing any difference.

wadmiraal’s picture

StatusFileSize
new607 bytes

Can 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.

gaele’s picture

Status: Postponed (maintainer needs more info) » Needs review

Hi, thanks for the patch. I'm currently away from the office. Will be back second half of March, and test your patch then.

wadmiraal’s picture

Status: Needs review » Postponed (maintainer needs more info)

Any news on this? Did you have the opportunity to try it out?

If it works, I will include it in the next release.

gaele’s picture

Not yet. I will test tomorrow and let you know.

gaele’s picture

Status: Postponed (maintainer needs more info) » Active

Sorry, 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.

wadmiraal’s picture

Status: Active » Closed (won't fix)

Well, 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.