php - PHPExcel memory still exhausted even with cell caching - other solutions -


<b>fatal error</b>:  allowed memory size of 134217728 bytes exhausted (tried allocate 78 bytes) in <b>/var/www/leanne/api/classes/phpexcel/cachedobjectstorage/phptemp.php</b> on line <b>66</b><br /> 

hi,

i asked this question few days ago , advised change code , use cell caching. while have changed code , attempted use cell caching, still getting memory error. desperate find solution this.

can advise on caching method best writing excel files ranging between 1 100,000 rows of data? if cell caching doesn't work, may need use solution allows me append xls file in same way csv version.

an example of current code below:

if ($count_prods > 0) {      $format = strtolower($export_data['output']);     $temp_file_location = '../temp/exports/products/';     $filename = 'data_' + $shop->id . '_' . $export_id . '_test';     $separator = ',';     $endrow = "\n";      $fh = fopen($temp_file_location . $filename . '.csv', 'a');      /*$cachemethod = phpexcel_cachedobjectstoragefactory:: cache_to_phptemp;     $cachesettings = array( ' memorycachesize ' => '8mb');     phpexcel_settings::setcachestoragemethod($cachemethod, $cachesettings);*/      $cachemethod = phpexcel_cachedobjectstoragefactory:: cache_to_sqlite;     phpexcel_settings::setcachestoragemethod($cachemethod);      $objphpexcel = new phpexcel();      $rowid = 2;     $counter = 1;     ($i = 0; $i < $count_prods; $i += $batchlimit) {         $csv = '';         $limit = $batchlimit * $counter;         $start = $i + 1;         $productdata = $productexport->getproductdata($start, $limit);          if ($counter == 1) {             //get column names             if ($format == 'csv') {                 $column_titles = implode(',', $productexport->product_fields);                 $column_no = count($column_titles);                 $csv = $column_titles . $endrow;             } else {                 $objphpexcel->getactivesheet()->fromarray($productexport->product_fields, null, 'a1');             }         }          //loop through data export array         foreach ($productdata $product_id => $product_details) {             $columnid = 'a';             foreach ($product_details $key => $value) {                 if ($format == 'csv') {                     $csv .= '"' . str_replace('"', '\'', $product_details[$key]) . '"' . $separator;                 } else {                     $objphpexcel->getactivesheet()->setcellvalue($columnid . $rowid, $product_details[$key]);                 }                 $columnid++;             }             if ($format == 'csv') {                 $csv = rtrim($csv, $separator);                 $csv .= $endrow;             }             $rowid++;         }         if ($format == 'csv') {             fwrite($fh, $csv);             $csv = '';         }          $counter++;     }     if ($format == 'csv') {         fclose($fh);     }      //if  xls file      if ($format == 'xls') {         //$objphpexcel = $objreader->load($temp_file_location . $filename . '.csv');         // $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5');         //$objwriter->save($temp_file_location . $filename . '.xls');         $objwriter = new phpexcel_writer_excel2007($objphpexcel);         $objwriter->save($temp_file_location . $filename . '.xlsx');     } 

you increase memory , time allocated script using:

ini_set('memory_limit', '2048m'); set_time_limit('1200');


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -