2

I have an associative array in php consisting of about 4k elements. Product Id and Product Name a sample row:

'434353', 'TeaCups'

So no big data. In fact the whole php array file is about 80kb. This is static data, so I won't be changing, deleting any data.

Considering the size of the array and the number of elements in it, Would it be better to access data from the array or I should create a database instead?

The data might be read about 20k times a day.

PS: Each time the data will be read, I will be fetching exactly one element

user3772
  • 1,199
  • 2
  • 11
  • 15
  • Accessing a database is much slower than accessing an array in memory. 80KB is very litle memory these days. – Barmar Apr 30 '15 at 22:55
  • If it's being read that often you might want to consider APC or memcached for keeping the data in memory. – Sean Apr 30 '15 at 22:58
  • 1
    It's a no brainer, avoid db for that since you're not querying anything and you don't need the overhead of connecting to the db. – N.B. Apr 30 '15 at 22:58
  • @SeanKenny Thanks, I was going to ask for that in another question. – user3772 Apr 30 '15 at 23:00
  • @SeanKenny Do you recommend APC or memcached for this specific case? – user3772 Apr 30 '15 at 23:01
  • i don't have the expertise to opine so I'll defer to this: http://stackoverflow.com/questions/815041/memcached-vs-apc-which-one-should-i-choose – Sean Apr 30 '15 at 23:04

1 Answers1

1

If this is static data, I recommend you store this data in a JSON format as a file, that you can access via PHP using the fopen() function.

However, if the data becomes bigger, like lets say, 2 GB, or even 200 MB, unless if you have a supercomputer, you should use the database and query from there.

Note that databases are usually only useful when you have a lot of information, or if you have too much information to process in a regular JSON.

  • I have opted for APC and array method. I dont suppose storing it in a json file, and reading/converting it to an array would be better than having the array itself stored in RAM. – user3772 May 01 '15 at 19:09