This article will introduce a solution to the memory leak in PHPExcel Allowed memory size of. Friends who have encountered this kind of problem can refer to it.
I am using PHPExcel to import a document with approximately 31 columns and 500 rows. After importing, PHP will report the following error:
Fatal error: Allowed memory size of 209715200 bytes exhausted (tried to allocate 35 bytes)
inX:wwwClassesPHPExcelCell.php on line 711
The solution is to add a method to the PHPExcel_Worksheet class:
The code is as follows
代码如下 |
复制代码 |
public function Destroy() {
foreach($this->_cellCollection as $index => $dummy) {
$this->_cellCollection[$index] = null;
}
}
并在 PHPExcel 类中增加方法:
public function Destroy() {
foreach($this->_workSheetCollection as $index => $dummy) {
$this->_workSheetCollection[$index]->Destroy();
$this->_workSheetCollection[$index] = null;
}
}
|
|
Copy code
|
public function Destroy() {
foreach($this->_cellCollection as $index => $dummy) {
$this->_cellCollection[$index] = null;
}
代码如下 |
复制代码 |
ini_set('memory_limit', '-1');
或
ini_set('memory_limit','265M')
|
}
And add methods in the PHPExcel class:
public function Destroy() {
代码如下 |
复制代码 |
memory_limit = 12M
|
foreach($this->_workSheetCollection as $index => $dummy) {
$this->_workSheetCollection[$index]->Destroy();
$this->_workSheetCollection[$index] = null;
}
}
代码如下 |
复制代码 |
php_value memory_limit 12M
|
|
Another way is to modify your php memory configuration and add in
Add a statement in the php file
The code is as follows
|
Copy code
ini_set('memory_limit', '-1');
or
ini_set('memory_limit','265M')
The code is as follows
|
Copy code
|
memory_limit = 12M
.htaccess file, add the following content
The code is as follows
|
Copy code
|
php_value memory_limit 12M
http://www.bkjia.com/PHPjc/632136.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632136.htmlTechArticleThis article will introduce a solution to the memory leak in PHPExcel Allowed memory size of. Friends who have encountered this kind of problem can Reference Reference. I am using PHPExcel to import about 31 columns one by one...
|
|
|
|