Caching method on reading

Topics: Developer Forum, User Forum
Jul 19, 2012 at 11:08 AM

Hi !

I'm trying to use cachingMethod to reduce memory using.

But I tried to use any method and i'd never seen any change about memory using.

My .xlsx file is around 60Mo, I know it's hudge...

Below some pieces of my code : 

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3;
if (PHPExcel_Settings::setCacheStorageMethod($cacheMethod) === FALSE) {
	echo 'ERROR caching method';
	return;
}

class chunkReadFilter implements PHPExcel_Reader_IReadFilter
{
	private $_startRow = 0;

	private $_endRow = 0;

	/**  Set the list of rows that we want to read  */
	public function __construct($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;
	}
}

/**  Identify the type of $inputFileName  **/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
echo 'File type is : ';
print($inputFileType . "\n") ;
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$filter1 = new MyReadFilter(1,2);
$objReader->setReadFilter($filter1);
$objPHPExcel = $objReader->load($inputFileName);
$objWorksheet = $objPHPExcel->getActiveSheet();

[SQL actions...]

$objPHPExcel->disconnectWorksheets();

for ($startRow = $beginLine; $startRow <= $nbLigne; $startRow += $chunkSize) {
	
	/**  Create a new Instance of our Read Filter, passing in the limits on which rows we want to read  **/
	$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
	
	/**  Tell the Reader that we want to use the new Read Filter that we've just Instantiated  **/
	$objReader->setReadFilter($chunkFilter);
	/**  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);
	print("\n\n\n\n");
	$mySqlWriter->InsertValue($title, preparInsert($sheetData, $startRow, $startRow + $chunkSize));
	$objPHPExcel->disconnectWorksheets();
}

Any idea about my error ?

 

Thank