Fatal error: Allowed memory size of bytes exhausted (tried to allocate bytes) in Excel5.php on line

Topics: User Forum
Jan 7, 2013 at 1:12 PM

Good day! Having a problem during reading .xls file (size ~21Mb).

I`we already tried to increase memory limit up to 64Mb.

Tried to use

 

PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;

 

and 

PHPExcel_CachedObjectStorageFactory::cache_to_discISAM; 

 

but I still get the same error. (not sure that I`we use`d that method correctly in my script...)

Tried to use $chunk.

My script is

<!--?php

error_reporting(E_ALL);
set_time_limit(0);

date_default_timezone_set('Europe/London');



?-->




PHPExcel Reader Example #12




PHPExcel Reader Example #12

Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)

<!--?php /** Set Include path to point at the PHPExcel Classes folder **/ set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/'); /** Include PHPExcel_IOFactory **/ include 'PHPExcel/IOFactory.php'; $inputFileType = 'Excel5'; // $inputFileType = 'Excel2007'; // $inputFileType = 'Excel2003XML'; // $inputFileType = 'OOCalc'; // $inputFileType = 'Gnumeric'; $inputFileName = './sampleData/brain.xls'; /** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */ class chunkReadFilter implements PHPExcel_Reader_IReadFilter { private $_startRow = 0; private $_endRow = 0; /** Set the list of rows that we want to read */ public function setRows($startRow, $chunkSize) { $this- -->_startRow = $startRow; $this->_endRow = $startRow + $chunkSize; } public function readCell($column, $row, $worksheetName = '') { // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { return true; } return false; } } echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; /** Create a new Reader of the type defined in $inputFileType **/ $objReader = PHPExcel_IOFactory::createReader($inputFileType); /* $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM; $cacheSettings = array( 'dir' => '/usr/local/tmp' ); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); */ $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp; $cacheSettings = array( 'memoryCacheSize' => '2000MB' ); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); echo '
'; /** Define how many rows we want to read for each "chunk" **/ $chunkSize = 1; /** Create a new Instance of our Read Filter **/ $chunkFilter = new chunkReadFilter(); /** Tell the Reader that we want to use the Read Filter that we've Instantiated **/ $objReader->setReadFilter($chunkFilter); /** Loop to read our worksheet in "chunk size" blocks **/ for ($startRow = 2; $startRow <= 2; $startRow += $chunkSize) { echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'
'; /** Tell the Read Filter, the limits on which rows we want to read this iteration **/ $chunkFilter->setRows($startRow,$chunkSize); /** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/ $objPHPExcel = $objReader->load($inputFileName); // Do some processing here $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); var_dump($sheetData); echo '

'; } /* $objPHPExcel->disconnectWorksheets(); unset($objPHPExcel); */ ?>
modified exampleReader12.php :)