Phpexcel Memory leak issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.