phpExcel中使用SqlLitecaching方法耗尽内存

我正在构build一个从数据库中获取数据的excel文件。 在某些情况下,excel在行和列方面都可能是非常大的。 在这种情况下,我得到关于内存耗尽的错误。

阅读在其他SO问题中给出的build议我设置我的代码使用SqlLite3caching方法与此代码:

// Redirect output to a client's web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="'.$data_rif.'_'.$nome.'_business_plan.xlsx"'); //header('Content-Disposition: attachment;filename="'.$data_rif.'_business_plan.xlsx"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d MYH:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3; if (PHPExcel_Settings::setCacheStorageMethod($cacheMethod)) { echo date('H:i:s') , " Enable Cell Caching using " , $cacheMethod , " method" , EOL; } else { echo date('H:i:s') , " Unable to set Cell Caching using " , $cacheMethod , " method, reverting to memory" , EOL; } // Create a new PHPExcel object $ea = new PHPExcel(); $ea->getProperties() ->setCreator($nome) ->setTitle('Business Plan') ->setLastModifiedBy($nome) ->setDescription('Jenius Business Plan') ->setSubject('Jenius Business Plan') ->setKeywords('excel jenius businessplan') ->setCategory('financial') ; $ews = $ea->getSheet(0); 

在这个修改之后,精化时间变长了,但是我仍然得到了一个耗尽的内存错误:

致命错误 :允许内存大小314572800字节用尽(试图分配85个字节)在/var/www/jdev/creditmanager/Classes/PHPExcel/CachedObjectStorage/CacheBase.php上线186

我在做什么错误的caching设置? 这个代码更小的excel创build没有任何不方便

这是如何填充excel的一个子集

 foreach($creds as $cred){ // dati generali dei singoli crediti $nome_soff = soff2name($cred['cod_soff'],$pdo); $data_acq = mysql2table($cred['data_acq']); $ammesso = $cred['ammesso']; $prezzo_acq = $cred['prezzo_acq']; $data_chius_table = mysql2table($cred['data_chius']); if($cred['caus_chius']!=''){$caus_chius = chius2name($cred['caus_chius'],$pdo);}else{$caus_chius='';} $credito = $cred['id_cre']; $last_inc = $pdo->query("SELECT max(data_inc) FROM incassi_row WHERE id_cre = '$credito'")->fetchColumn(); $perc_worst = $pdo->query("SELECT azioni_head.perc_worst FROM azioni_row JOIN azioni_head ON azioni_row.id_az = azioni_head.id_az WHERE id_cred = '$credito'")->fetchColumn(); if($cred['data_chius']<>'0000-00-00'){$data_chius = mysql2table($cred['data_chius']);}else{$data_chius = '';} if($last_inc<> ''){$last_incasso = mysql2table($last_inc);}else{$last_incasso='';} /*$row_array1=array($cred['id_cre'],$cred['serie'],$nome_soff,$data_acq,prot2name($cred['cedente'],$pdo), $ammesso,$prezzo_acq,prot2name($cred['originator'],$pdo),$cred['stato'],$data_chius, $caus_chius,$last_incasso,$perc_worst.'%','','','','', '','Acquisto','=SUM(U'.$k.':EJ'.$k.')'); */ $row_array1=array($cred['id_cre'],$cred['serie'],'','','','','','','','', '','','','','','','','','Acquisto','=SUM(U'.$k.':EJ'.$k.')'); for($anno = $annoMin; $anno<=$annoMax; $anno++){ for($mese = 1; $mese <= 12; $mese++){ $mese = sprintf("%02s", $mese); $inizio = $anno.'-'.$mese.'-01'; $fine = $anno.'-'.$mese.'-31'; if(($cred['data_acq']>=$inizio) && ($cred['data_acq']<=$fine)){ array_push($row_array1,$cred['prezzo_acq']); }else{ array_push($row_array1,'0.00'); } } } array_push($row_array1,'=SUM(U'.$k.':EJ'.$k.')'); $ews->fromArray($row_array1, ' ', 'A'.$k);