PHPExcel - write / add to chunks

I am using PHPExcel framework to try and write out a very large excel document from a mysql query.

Everything works fine until I hit the mark on line 5000 (or thereabouts) where the page will be marked with an error:

Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate yyy bytes) in zzz on line aaa


I know this is documented and I've adjusted the memory allocation on the server, but I'm still on the ceiling nonetheless. I also tried to disable formatting, but I actually need it.

So, is there a way to write in small chunks or add to an excel document so that I don't run out of memory allocation? I think in the lines of writing the page says 1000 lines, then redirects to itself and processes the next 1000 using GET for tracking. For example:


then redirect to



But I can't seem to find a way to add to an existing document without opening the whole thing.


source to share

1 answer

There is no way to write in chunks, although a common mistake is people load their mysql data into an array and then project the array by setting the Excel cell data. It is more memory efficient for setting cell data as it traverses the result set of a mySQL query.

If you need to keep memory usage to a minimum, which caching method do you use? Cell caching is slower but can save significant amounts of memory.



All Articles