Which is faster / more efficient - lots of little MySQL queries or one big PHP array?

前端 未结 6 1016
离开以前
离开以前 2021-02-06 01:55

I have a PHP/MySQL based web application that has internationalization support by way of a MySQL table called language_strings with the string_id,

6条回答
  •  臣服心动
    2021-02-06 02:16

    Agree with what everybody says here.. it's all about the numbers.

    Some additional tips:

    1. Try to create a single memory array which holds the minimum you require. This means removing most of the obvious redundancies.

    2. There are standard approaches for these issues in performance critical environments, like using memcached with mysql. It's a bit overkill, but this basically lets you allocate some external memory and cache your queries there. Since you choose how much memory you want to allocate, you can plan it according to how much memory your system has.

    3. Just play with the numbers. Try using separate queries (which is the simplest approach) and stress your PHP script (like calling it hundreds of times from the command-line). Measure how much time this takes and see how big the performance loss actually is.. Speaking from my personal experience, I usually cache everything in memory and then one day when the data gets too big, I run out of memory. Then I split everything to separate queries to save memory, and see that the performance impact wasn't that bad in the first place :)

提交回复
热议问题