cgajardo
cgajardo

Reputation: 364

Save arrays strategy in PHP

I came to this issues recently where I have to decide if I save a list of arrays all in one file or keep it in separeted files.

Here's the deal. I have an array of arrays, I'll simplify the example:

countries['america'] = array('chile', 'brazil', 'usa');
countries['europe'] = array('france', 'italy', 'spain');
...and so.

So, I could save all the arrays in one big file (name it 'world'), and whenever I'll have to query a country in a continent I'll load all the file in memory.

Or, I could save each array in a different file (name it 'america', 'europe', etc), and whenever I'll have to query a country in a continent I'll load the corresponding file.

I know it all comes to sizes, so imagine the world has 10 continents and each continent has 2000 countries.

What is the best approach?

Note: this is a performance issue and I prefer to avoid calling a database.

Upvotes: 1

Views: 140

Answers (1)

Vestimir Markov
Vestimir Markov

Reputation: 330

You can store the array into in-memory cache system, like xcache or memcached. This way your data will be kept into the ram and it will be far more speedy and lightweight than database or file-based storage.

See xcache and memcached

Upvotes: 1

Related Questions