Raza448 / php-excel-reader

Automatically exported from code.google.com/p/php-excel-reader
0 stars 0 forks source link

Memory usage #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi there,
good to see that somebody picked up development of this class.

For quite some time I was worried by the heavy memory usage Excel_Reader
shows when dealing with larget excel files.
Today I digged around a bit in the code, and I was able to reduce memory
usage (memory_get_peak_usage) down from 71MB to 16MB for a ~11.000 rows
excel file.
I removed / commented out 4 lines in function addcell(), namely
$this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col +
$this->_coloffset]['raw'] = $raw;
$this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col +
$this->_coloffset]['type'] = $type;
$this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col +
$this->_coloffset]['format'] = $format;
$this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col +
$this->_coloffset]['formatIndex'] = $formatIndex;

Those 4 entries alone were responsible for such a huge overhead, and I
didn't really need those information for my further processing. And as it
seems, the class itself doesn't either.

What I'd really like to see and what I was already searching for, is a
'streaming' reading of excel files, where you don't need to have the whole
excel file in memory to process.
But alas, such thing doesn't seem to exist, so for the time being I'm
content with such a dramatic decrease in memory usage with the currently
available class.

Original issue reported on code.google.com by spoon...@gmx.net on 5 Dec 2008 at 1:49

GoogleCodeExporter commented 8 years ago
Perhaps this would be good as an option? So you could disable the data values 
that
you don't want to work with to conserve memory. I've not used a sheet anywhere 
close
to 11,000 rows, so I haven't faced any memory problems.

Original comment by matthew....@gmail.com on 5 Dec 2008 at 3:59

GoogleCodeExporter commented 8 years ago
All I founded that CPU usage when tasting with IE 6 and IE 7 is very high and
changing constantly. Nothing similar when tasting with other browsers, Firefox, 
Opera
nor Chrome. You were right about reduce memory usage. Thank you very much.

Original comment by veljkovi...@gmail.com on 13 Dec 2008 at 2:57

GoogleCodeExporter commented 8 years ago
This is server-side PHP code. The browser being used shouldn't matter.

Original comment by matthew....@gmail.com on 16 Dec 2008 at 8:10

GoogleCodeExporter commented 8 years ago
Without knowing much detail about Comment 2, i could suggest the poster meant 
that
the browser consumes a lot of CPU if this class is used in some kind of AJAX 
call,
where the JS is waiting for results from whatever is being read from the Excel 
file.
In any case, you're correct.

And on topic to the issue: i do occasionally process large Excel files also, and
seeing this RAM saver work-around is helpful. i second the idea of making these 
optional.

Original comment by thooke...@gmail.com on 4 Jan 2009 at 6:00

GoogleCodeExporter commented 8 years ago
Thanks for this comment, spoon.... 

 I was getting "PHP Allowed memory size of 33554432 bytes exhausted " errors, and using ini_set to keep 
increasing memory_limit was not helping and making me nervous.  Removing those 
lines eliminated the memory 
error.

File I have was processing an eight-column by 9000-row excel file that took up 
just 1.7MB of disk space.

Original comment by brooh...@gmail.com on 20 Jan 2009 at 1:25

GoogleCodeExporter commented 8 years ago
I would like to add another vote for additions to make this a streaming reader.
At work, I have to process inventory files that are sent in .xls format.  They 
can be
anywhere between 100 lines and 40,000 lines.

Of course, trying to load the 40k one lags the server so bad that it's actually
easier to go in and save the file as a csv....

Original comment by 1234...@gmail.com on 23 Jan 2009 at 10:20

GoogleCodeExporter commented 8 years ago
Changing this to be a streaming reader would be out of my league. I am, however,
introducing a second parameter to the constructor which will cause the reader 
to NOT
populate the 'cellsInfo' array, and conserve memory.

Original comment by matthew....@gmail.com on 26 Jan 2009 at 5:56

GoogleCodeExporter commented 8 years ago
I noticed something else in relation to the memory/CPU usage...Excel Reader 
seems to 
read all "visible" rows in a sheet, by visible, I mean rows that don't have any 
data,  
but can be seen when scrolling down by dragging the scroll bar.
Its a little difficult to explain, if you were to scroll down say about 15k 
rows and 
entered any character/number in row #15,001 and deleted it subsequently, and 
then ran 
the script, it will count 15,0001 rows although the actual data may only be in 
the 
first few rows - does that make sense?

I could of course upload an example file if its not very clear.

Original comment by karthikp...@gmail.com on 26 Jan 2009 at 6:10

GoogleCodeExporter commented 8 years ago
Version 2.1 is released which adds the second flag to the constructor

Original comment by matthew....@gmail.com on 26 Jan 2009 at 6:15

GoogleCodeExporter commented 8 years ago
I have error:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 
71 bytes) 

my file is just 7Kb, there are only 2 records in one sheet in the file.

Here is my code :

$data = new Spreadsheet_Excel_Reader();
$data->read($desFile);
....

It was broken out when run $data->read($desFile);

I dont know where I am wrong..

Give me help, plz!!!!!!!

Original comment by markki...@gmail.com on 26 Mar 2011 at 9:11