Using Phpexcel to generate Excel documents is more memory-intensive, and sometimes it may take a loop to cut big data into several small Excel documents to avoid running out of memory.
However Phpexcel exists in the circular references (which seems to have not been addressed in the latest 1.6.5 release), if you build Phpexcel and Phpexcel_writer_exce repeatedly during an HTTP request L5 object instances to complete multiple Excel document generation operations, all constructed object instances cannot be released in a timely manner before the HTTP request ends, causing a memory leak.
The workaround is to add a method to the Phpexcel_worksheet class:
Public Function Destroy () {
foreach ($this->_cellcollection as $index = + $dummy) {
$this->_cellcollection[$index] = null;
}
}
and add the method in the Phpexcel class:
Public Function Destroy () {
foreach ($this->_worksheetcollection as $index = + $dummy) {
$this->_worksheetcollection[$index]->destroy ();
$this->_worksheetcollection[$index] = null;
}
}
Then explicitly call Phpexcel::D Estroy () to handle circular references where resource recycling is required. Note that the __destruct () method is called only when the object is considered to be free, so the processing of the circular reference cannot be placed on the __destruct ().
Phpexcel Memory leak issues