How to deal with phpexcel read excel memory release

when php uses phpexcel to read excel, if the excel itself has more rows and rows, it is easy to cause
Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes)
insufficient memory error,

so I wrote a script that uses phpexcel filter to achieve block-level reading, but each time the read is finished, the memory occupied will not be released, resulting in an error that Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) does not have enough memory after multiple reads.

using unset,=null has no obvious effect. After looking up the information,
adds Desroty methods to the PHPExcel_Worksheet and phpexcel classes, and explicit calls do not use

.
public function Destroy() {
    foreach($this->_cellCollection as $index => $dummy) {
        $this->_cellCollection[$index] = null;
    }
    $this->_cellCollection = null;
}

public function Destroy() {
    foreach($this->_workSheetCollection as $index => $dummy) {
        $this->_workSheetCollection[$index]->Destroy();
        $this->_workSheetCollection[$index] = null;
    }
    $this->_workSheetCollection = null;
}

which boss has a solution?

Mar.04,2021

has found the answer to the problem. Every time you finish load the excel file and read it, call the disconnectWorksheets () method provided by phpexcel itself with the phpexcel object generated by load, which assigns a null value to the property of phpexcel and frees up memory resources

.
Menu