Array max size

greg's picture

He has: 1,581 posts

Joined: Nov 2005

What would be considered a max size guide for arrays in terms of data in them.

For example, is 2,000 words acceptable?

I know it depends on the .ini memory limit settings, and of course available RAM etc.
But what is a reasonable amount of data to be put in arras. I usually only use them in $_SESSIONS, for user data and other things often a few characters.
But have come across a situation where it would be very useful to store a lot fo info in an array. About 2,000 words

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

2000 words is not as big as you think. An average of 5 characters per word would be 10,000 bytes or less than 10k of memory. Not enough to worry about.

You will very rarely ever hit a cap with storing text in a variable. You will only ever really have to worry about memory limits when doing some image manipulation or something.

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Ok thanks.

I got the size thing, but with a few thousand users it could get to be a few MB. Still not loads with todays GB, but anything is something.

"anything is something"
That's profound that is Greg!

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

If you have several thousand users on your server at the same time, a few MB of memory for your $_SESSION data will be the least of your concerns. Smiling

He has: 1,758 posts

Joined: Jul 2002

Why would you be storing all of your user info in an array?

Surely it would be better to start using a database if you have lots of users?

just out of interest like...

Andy

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Not sure why you thought it was user info??
Arrays are used in many circumstances, not just user data.

It's for a musical website. The site has a page which displays all the musicians albums and next to each album is a link for lyrics and samples for each album.
When a link to lyrics or samples is clicked, it goes to the same page, but with additional GET info to determine if user selected mp3 samples or lyrics.
(I use the same page as there isn't much data required in the displaying of all albums.)

In the GET is also which album's lyrics the user wanted to view.
Then in a separate file I have all the lyrics for all the albums, KEY is song name and VALUE is the lyrics.

As the file is queried after the GET stuff, a var is already set to detrmine the album to user wants, so the separate file uses that var to know which array data to get for which album.

I asked about storage for arrays as I could easily have had all the data for lyrics for each song for each album within the same file, but it's al ot of data.
But mainly because adding an extra set of song lyrics to the separate array file is easier when the artist adds a new album.
And also, is easier to do within the ACP I created, to make it easy for them to do themselves.

The displaying of lyrics is simply a foreach on the array it gets as per the GET data.

(you did ask Laugh)

greg's picture

He has: 1,581 posts

Joined: Nov 2005

I know what you where all thinking... there was a reason why I couldn't..

I managed to convince my client to use a host that provides a database.
So yes, now the arrays are of course scrapped and replaced by mysql.

I think she is already convinced the move was worthwhile from the ACP I have built now there is a DB.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.