Memory Issue to just load Excel 2007 sheet even after set time limit and ini_set memory

Topics: Developer Forum, Project Management Forum, User Forum
Jun 25, 2012 at 4:56 PM

Hi.  I am attempting to read an Excel 2007 worksheet.  I set the memory limit to be unlimited and for it not to time out.  Yet, I am still getting the fatal error of allowable memory size limite:


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /var/www/html/PHPExcel/Classes/PHPExcel/Cell.php on line 506 Call Stack: 0.0004 638528 1. {main}() /var/www/html/phase1/excel7.php:0 0.0067 752736 2. PHPExcel_Reader_Excel2007->load() /var/www/html/phase1/excel7.php:48 11.6364 134161144 3. PHPExcel_Worksheet->getCell() /var/www/html/PHPExcel/Classes/PHPExcel/Reader/Excel2007.php:1013 11.6364 134162784 4. PHPExcel_Cell::coordinateFromString() /var/www/html/PHPExcel/Classes/PHPExcel/Worksheet.php:1119 11.6364 134162984 5. preg_match() /var/www/html/PHPExcel/Classes/PHPExcel/Cell.php:506


Any ideas or help is greatly appreciated.  I am at a loss. 



ini_set('memory_limit', '-1');


//file type
$inputFileType = 'Excel2007';

//get file name
$inputFileName = "../files/samplesheet.xlsx";
$sheetname = 'testSheet1';

//check that file exists
    /**  Create a new Reader of the type defined in $inputFileType  **/
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    /**  Advise the Reader that we only want to load cell data  **/

    /**  Advise the Reader of which WorkSheets we want to load  **/
    /** Load $inputFileName to a PHPExcel Object  **/
    $objPHPExcel = $objReader->load($inputFileName);
    /** Get number of sheets **/
    $total_sheets = $objPHPExcel->getSheetCount();
    /** Get all sheet names **/
    $allSheetName = $objPHPExcel->getSheetNames();


Jun 25, 2012 at 5:18 PM

The error message you're getting:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)

tells me that your memory is not unlimited, but set at 128MB.


If you want to reduce memory usage, enable cell caching

Jun 25, 2012 at 7:24 PM


Thanks for responding.

I thought with this code: 

ini_set('memory_limit', '-1');

i am able to set my memory limit to be unlimited.

is that not the case?


How do I enbale cell caching as you suggested?

Jun 25, 2012 at 8:39 PM

Changing the memory limit from within your code only works if your host hasn't disabled it.


Use of cell caching is described in section 4.2.1 of the developer documentation

Jun 26, 2012 at 3:38 AM

Mark -- thanks.  you are right about the memory limit.  I have the sys admin change the memory limit to 512MB and it is working.  And thanks for the direction for the cell caching.  That will come in handy.  Many thanks.