在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  Office/ phpexcel讀取excel內(nèi)存釋放怎么處理

phpexcel讀取excel內(nèi)存釋放怎么處理

php使用phpexcel讀取excel的時(shí)候,如果excel本身行列較多,很容易引起
Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes)
內(nèi)存不夠的報(bào)錯(cuò),

于是我寫了一段腳本,利用phpexcel過濾器實(shí)現(xiàn)塊級(jí)讀取,但是每次讀取完畢了,占用的內(nèi)存不會(huì)釋放掉,造成多次讀取以后還是會(huì)報(bào)出Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes)內(nèi)存不夠的錯(cuò)誤?

使用unset,=null都沒有明顯的作用,后面查了下資料,
在PHPExcel_Worksheet和phpexcel類中加了Desroty方法,并且顯式調(diào)用也沒有用

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;
}

請(qǐng)問哪位大佬有解決方案?。?/p>

回答
編輯回答
嘟尛嘴

已找到解決問題答案,每次load完excel文件并且讀取完成以后,用load產(chǎn)生的phpexcel對(duì)象調(diào)用一下phpexcel本身提供的disconnectWorksheets()方法,會(huì)為phpexcel的屬性賦予null值,釋放內(nèi)存資源

2018年1月4日 20:22