1

I have a PHP file that contains a large array (about 90KB). I'm considering moving it to the database however I'm not sure it's worth the trouble.

In general, am I likely to run into problems with a 90KB array? Will I get any speed improvement by moving the data to a database?

1
  • Like John said, arrays are much faster. I've built a caching framework which stores arrays into files (like the one you're talking about) and it's amazing when it comes to performance. Brilliant for AJAX calls. Commented Jun 12, 2012 at 1:46

1 Answer 1

6

Arrays are much faster then accessing a database. Accessing a database is one of the more expensive things you can do in PHP while accessing an array is one of the fastest.

Sign up to request clarification or add additional context in comments.

3 Comments

What if you only need to access one element? Doing a quick DB query on an indexed table might be faster than parsing a file and assigning 90 kB worth of array variables. There has to be a cross over somewhere where the DB query becomes more beneficial. What about things like sorting? Surely an indexed DB would be faster than an array.
Mike makes a good point, I wonder at what point it becomes inefficient to load a PHP array and faster to do a DB query.
Nope, not @ 90Kb. This is small enough to get cached in the VFAT cache and even on a cache-miss will generate only one or two physical I/Os. The CPU overhead is trivial. The main things are to (i)ensure that you only write back on dirtied content, and (ii) to have a contention strategy if you have parallel transactions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.