0

I have an error on upload files with aprox 130.000 rows (23MB). The code works good with small files but when I try to upload bigger ones this error always comes out. I have already tried the cell caching method to reduce memory usage but the error remains. In my php.ini the parameters are memory_limit=128M / upload_max_filesize=64M / post_max_size=64M.

Warning: simplexml_load_string(): Memory allocation failed in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): Entity: line 2: parser error : Memory allocation failed : xmlSAX2Characters in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): "><c r="I935190" s="9"/></row><row r="935191" spans="9:9" x14ac:dyDescent="0.25" in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): ^ in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): Memory allocation failed : building attribute in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): Memory allocation failed : building attribute in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): Memory allocation failed in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): Entity: line 2: parser error : Extra content at the end of the document in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652
Warning: simplexml_load_string(): "><c r="I935190" s="9"/></row><row r="935191" spans="9:9" x14ac:dyDescent="0.25" in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652

And when I try the uploading again it appear:

Warning: simplexml_load_string(): Memory allocation failed : growing buffer in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652

Warning: simplexml_load_string(): Memory allocation failed : growing buffer in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652

A piece of the php code, all warnigs appear on the 9th line when I load the file:

$total = count($_FILES["file"]["name"]);

for($j=0; $j<$total; $j++){


  $tmpFilePath =$_FILES["file"]["tmp_name"][$j];

  if ($tmpFilePath != ""){

    $newFilePath = 'ficheros/'. $_FILES["file"]["name"][$j];
  }
    if(move_uploaded_file($tmpFilePath, $newFilePath)){

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($newFilePath);

$sheetCount = $objPHPExcel ->getSheetCount();
$sheetNames = $objPHPExcel -> getSheetNames();

$objWorksheet = $objPHPExcel -> getSheetByName("Sheet1");

$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$rows = array();
for ($row = 2; $row <= $highestRow; ++$row) {
    for ($col = 0; $col <= $highestColumnIndex; ++$col) {
      $rows[$col] = $objWorksheet->getCellByColumnAndRow($col, $row)->getCalculatedValue();

}

mysql_query..
}
}

Thanks in advance

escalas
  • 25
  • 5
  • Even with cell caching, it may be that 128M simply isn't enough for this file; a 23MB file doesn't mean a great deal, because it's compressed size. What really matters is the number of cells in the workbook: http://stackoverflow.com/questions/3537604/how-to-fix-memory-getting-exhausted-with-phpexcel – Mark Baker Jan 27 '17 at 09:43
  • Thanks @MarkBaker for the quick response. I have changed memory_limit to 4000 because the excel has 3,9 million cells. Now I'm getting the browser error ERR_CONNECTION_RESET in large files. Do you know what can cause this error ? – escalas Jan 30 '17 at 09:58
  • Quite probably the fact that the file is simply too large to work with in PHP's time/memory restrictions (or perhaps an apache timeout). Consider running this data load as a background process and/or chunk reading the file so that you're not loading it all into memory in one go – Mark Baker Jan 30 '17 at 10:13
  • @MarkBaker - Thanks the CONNECTION problem is solved. I've tried to apply chunk reading but even with "chunkSize=2" I'm getting the previous error in load($filename): Warning: simplexml_load_string(): Memory allocation failed : growing buffer in C:\xampp\htdocs\lib\PHPExcel\Reader\Excel2007.php on line 652 I don't find the problem, I have checked all the time/memory restrictions. – escalas Jan 31 '17 at 12:57

0 Answers0