php读取excel 报错_php读取excel内存溢出
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)塊級讀取,但是每次讀取完畢了,占用的內(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;
}
已找到解決問題答案,每次load完excel文件并且讀取完成以后,用load產(chǎn)生的phpexcel對象調(diào)用一下phpexcel本身提供的disconnectWorksheets()方法,會(huì)為phpexcel的屬性賦予null值,釋放內(nèi)存資源
這種方法聽說可以逐行導(dǎo)入內(nèi)存 ,待測試https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-files/
總結(jié)
以上是生活随笔為你收集整理的php读取excel 报错_php读取excel内存溢出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sm2和sm4加密算法浅析
- 下一篇: 动态规划算法php,php算法学习之动态