im usando PHPExcel per leggere i file .xls. Ho poco tempo piuttosto che incontroLettura del file .xls tramite PHPExcel genera Errore fatale: dimensione della memoria consentita ... anche con il lettore chunk
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 730624 bytes) in Excel\PHPExcel\Shared\OLERead.php on line 93
dopo qualche googling, ho cercato chunkReader evitare questa (menzionato anche su PHPExcel homesite), ma ancora im stucked con questo errore.
Il mio pensiero è che, tramite lettore chunk, leggerò il file parte per parte e la mia memoria non sarà troppo piena. Ma ci deve essere qualche grave perdita di memoria? O stai liberando un pò di memoria cattiva? Ho anche provato ad aumentare la ram del server a 1 GB. La dimensione del file, che sto cercando di leggere è di circa 700k, che non è tanto (im anche leggendo ~ 20MB pdf, xlsx, docx, doc, etc file senza problemi). Quindi presumo ci possa essere solo un troll minore che ho trascurato.
codice simile a questo
function parseXLS($fileName){
require_once dirname(__FILE__) . './sphider_design/include/Excel/PHPExcel/IOFactory.php';
require_once dirname(__FILE__) . './sphider_design/include/Excel/PHPExcel/ChunkReadFilter.php';
$inputFileType = 'Excel5';
/** Create a new Reader of the type defined in $inputFileType **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Define how many rows we want to read for each "chunk" **/
$chunkSize = 20;
/** 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 **/
/** $startRow is set to 2 initially because we always read the headings in row #1 **/
for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) {
/** 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($fileName);
// Do some processing here
// Free up some of the memory
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
}
}
E qui è il codice per chunkReader
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;
}
}
Ho trovato questo collegamento un po 'di tempo fa, ma non mi hanno spostato oltre allora iam ora. Durante l'utilizzo di chunk reader, sto ancora ottenendo lo stesso errore, anche con getDataOnly impostato su true ... –