Home > Backend Development > PHP Tutorial > PHPExcel Allowed memory size of memory leak solution_PHP tutorial

PHPExcel Allowed memory size of memory leak solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:56:56
Original
2151 people have browsed it

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')
Modify php.ini (recommended)
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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template