Page 1 of 1
limit to the size of an array?
Posted: Sun Sep 05, 2004 7:52 am
by malcolmboston
I am currently developing a large web application that may hold 1000's if not millions of records in the database.
now lately i have been starting to, instead of doing while loops to print out data, firstly put it all in an array and then use for loop to print out what i want.
I much prefer this way as i find it easier to handle what is getting outputted, however i am worried about an array getting too large.
I am just wondering whats the limit and what actually happens if it exceeds it?
Thanks
Mal
Posted: Sun Sep 05, 2004 10:39 am
by feyd
the limit is the alotted memory you gave php. You'll likely get a memory limit exceeded error when it happens. Select wisely, young padawan.

Posted: Sun Sep 05, 2004 4:21 pm
by timvw
virtually every RDBMS has a way to get only a part of the resultset a query would return. MySQL fe has LIMIT clause, MS SQL "TOP????" , ...
Or you could specify your query more, so you only get rows you actually want to output

Posted: Sun Sep 05, 2004 5:50 pm
by McGruff
What about using an iterator (& iterator decorators to add presentational stuff). That avoids copy arrays altogether.
Posted: Thu Sep 09, 2004 7:37 pm
by lazy_yogi
Listen to Micky G.
Iterators are definitely the way to go.
Posted: Fri Sep 10, 2004 6:58 am
by malcolmboston
timvw wrote:
Or you could specify your query more, so you only get rows you actually want to output

it is already a shortened query, however as i
already stated, i have started putting all data into an array and then outputting from there.
ive never learnt about iterators yet, looks like i'll have to go have a look....
Posted: Tue Sep 28, 2004 8:42 am
by malcolmboston
is there anyway of finding the size in MB/KB of an array within PHP itself?
or can it only be done with task managers?
Posted: Tue Sep 28, 2004 9:48 am
by feyd
iterating through the array, summing the string lengths of indices and values should give you a rough estimate. Note: remember to check the type, int's are 4 or 8 bytes; decimals are 4, 8, or 16 bytes; strings could easily be double byte characters. On a quick run through the functions, I didn't see an internal memory usage gauges..
Posted: Tue Sep 28, 2004 9:59 am
by McGruff
See last few posts here:
viewtopic.php?t=19906&start=45.
You really, really want to use iterators though.