limit to the size of an array?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

limit to the size of an array?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :P
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 :)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

What about using an iterator (& iterator decorators to add presentational stuff). That avoids copy arrays altogether.
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Listen to Micky G.
Iterators are definitely the way to go.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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....
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

See last few posts here: viewtopic.php?t=19906&start=45.

You really, really want to use iterators though.
Post Reply