1

Addtitional info: I'm running this from the command line. CentOS 6, 32GB Ram total, 2GB Memory for PHP. I tried increasing the memory limit to 4GB, but now I get a Fatal error: String size overflow. PHP maximum string size is 2GB.

My code is very simple test code:

$Reader = new SpreadsheetReader($_path_to_files . 'ABC.xls');
$i = 0;
foreach ($Reader as $Row)
{   $i++;
    print_r($Row);
if($i>10) break;

}

And it is only to print 10 rows. And that is taking 2 Gigabytes of memory?

The error is occuring at line 253 in excel_reader2.php

Inside class OLERead, inside function read($sFilenName)

Here is the code causing my exhaustion:

if ($this->numExtensionBlocks != 0) {

        $bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4;

    }



    for ($i = 0; $i < $bbdBlocks; $i++) { // LINE 253

        $bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);

        $pos += 4;

    }
Community
  • 1
  • 1
Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120
  • Except you're not using PHPExcel, so why is your question tagged `PHPExcel`? – Mark Baker Aug 31 '13 at 10:27
  • I was under the false impression that this uses PHPExcel. It actually uses php-excel-reader: "XLS file parsing is done with php-excel-reader". Sorry about that. – Buttle Butkus Sep 01 '13 at 03:19
  • @MarkBaker thanks for your edits and comment. I managed to solve my problem, but still wonder how 2GB of memory got used up processing a 287KB file. – Buttle Butkus Sep 01 '13 at 03:49

1 Answers1

1

I solved the problem. It turned out to be somewhat unrelated to the php code.

The program I am writing downloads .xls, .xlsx, and .csv files from email and FTP. The .xls file that was causing the memory overflow was downloaded in ASCII mode instead of Binary.

I changed my default to binary mode, and added a check that changes it to ASCII mode for .csv files.

I still find it strange that the program creates a 2GB string because of that. If there are no line breaks in the binary file, then I can see perhaps how the entire file might end up in one string. But the file is only 286KB. So, that's strange.

Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120
  • 1
    The xls file is loaded into memory as a single binary string, and then parsed into blocks and sub-blocks (streams and substreams) each of which exists concurrently in memory before the substreams are analysed for the actual values they contain; and at the same time, the array that is being built from the content is also in memory.... while I wouldn't expect the file to take up 2GB of memory, I could easily believe it would take 20MB or more just for the parsing, and more for the array that is being built – Mark Baker Sep 01 '13 at 10:16