I got an extra 80MB memory consumption after loading an 2.44MB Excel file

Topics: Developer Forum, Project Management Forum, User Forum
Sep 7, 2012 at 2:50 AM

//The code:

	$objReader = PHPExcel_IOFactory::createReader('Excel5'); 
        echo "after createReader,memory_get_usage:".(memory_get_usage()/1000000)."MB</br>";        
        $objPHPExcel = $objReader->load($excelFileName);$objReader='';
        echo "after readerload,memory_get_usage:".(memory_get_usage()/1000000)."MB</br>";
        $sheet = $objPHPExcel->getSheet(1);
        $sheet=null;unset($sheet);
        $objPHPExcel=null;unset($objPHPExcel); 
        echo "after set objPHPExcel and sheet to  null,memory_get_usage:".(memory_get_usage()/1000000)."MB</br>";
        die();



//The output:
/*

after createReader,memory_get_usage:12.033416MB
after readerload,memory_get_usage:92.257536MB
after set $objPHPExcel and $sheet to null,memory_get_usage:92.257432MB

*/

//The question:
//How to minimize the extra 80MB memory usage?
//The way by setting an variable to NULL and then unset the variable seems not work.  

Sep 7, 2012 at 7:24 AM

is there anyway to cut off some properties of phpExcel ?

Coordinator
Sep 7, 2012 at 7:37 AM

There are plenty of documented ways of reducing the memory usage of PHPExcel:

  • When loading files: If you only want data, and aren't worried about the formatting of the content, then the readerssetReadDataOnly(TRUE) option, or setLoadSheetsOnly() to only load those worksheets that you need.
  • Reading a file in "chunks" so that it isn't all "memory resident" at the same time.
  • Cell caching

These are documented features, and there's plenty of information about using theme here on the forum.

 

 

Sep 7, 2012 at 7:56 AM
MarkBaker wrote:

There are plenty of documented ways of reducing the memory usage of PHPExcel:

  • When loading files: If you only want data, and aren't worried about the formatting of the content, then the readerssetReadDataOnly(TRUE) option, or setLoadSheetsOnly() to only load those worksheets that you need.
  • Reading a file in "chunks" so that it isn't all "memory resident" at the same time.
  • Cell caching

These are documented features, and there's plenty of information about using theme here on the forum.

 

 

Thank u very much.

 

1.How to read a file in "chunks" ? PhpExcel seems to be load an excel file all by once.

2 About 'Cell caching' ,you mean using memocache or gzip ? I have already used this.

Coordinator
Sep 7, 2012 at 9:18 AM
Edited Sep 7, 2012 at 9:21 AM

By default, PHPExcel will load the entire file, but it can read only parts of the file if you tell it which parts you want to read.

There is an entire document in the /Documentation directory called "PHPExcel User Documentation - Reading Spreadsheet Files.doc" all about reading files. This explains how to read only the data (not the formatting) from a file; how to read only named worksheets from a file, and how to read only certain cells from a worksheet using a read filter, and so to the file in "chunks".

 

You will also find sample code demonstrating a lot of the methods that are described in that document in the /Documentation/Examples/Reader directory.

 

Sep 12, 2012 at 7:35 AM
MarkBaker wrote:

By default, PHPExcel will load the entire file, but it can read only parts of the file if you tell it which parts you want to read.

There is an entire document in the /Documentation directory called "PHPExcel User Documentation - Reading Spreadsheet Files.doc" all about reading files. This explains how to read only the data (not the formatting) from a file; how to read only named worksheets from a file, and how to read only certain cells from a worksheet using a read filter, and so to the file in "chunks".

 

You will also find sample code demonstrating a lot of the methods that are described in that document in the /Documentation/Examples/Reader directory.

 

Thanks a lot