How many MySQL queries should I limit myself to on a page? PHP / MySQL

后端 未结 10 1361
春和景丽
春和景丽 2020-12-10 13:16

Okay, so I\'m sure plenty of you have built crazy database intensive pages...

I am building a page that I\'d like to pull all sorts of unrelated database informati

相关标签:
10条回答
  • 2020-12-10 13:45

    Premature optimisation is a problem like people have mentioned before, but that's where you're crapping up your code to make it run 'fast'. But people take this 'maxim' too far.

    If you want to design with scalability in mind, just make sure whatever you do to load data is sufficiently abstracted and calls are centralized, this will make it easier when you need to implement a shared memory cache, as you'll only have to change a few things in a few places.

    0 讨论(0)
  • 2020-12-10 13:46

    As many as needed, but not more.

    Really: don't worry about optimization (right now). Build it first, measure performance second, and IFF there is a performance problem somewhere, then start with optimization.

    Otherwise, you risk spending a lot of time on optimizing something that doesn't need optimization.

    0 讨论(0)
  • 2020-12-10 13:48

    Wordpress, for instance, can pull up to 30 queries a page. There are several things you can use to stop MySQL pull down - one of them being memchache - but right now and, as you say, if it will be straightforward just make sure all data you pull is properly indexed in MySQL and don't worry much about the number of queries.

    If you're using a Framework (CodeIgniter for example) you can generally pull data for the page creation times and check whats pulling your site down.

    0 讨论(0)
  • 2020-12-10 13:52

    If you need the queries, you should just use them.

    What I always try to do, is to have them executed all at once at the same place, so that there is no need for different parts (if they're separated...) of the page to make database connections. I figure it´s more efficient to store everything in variables than have every part of a page connect to the database.

    0 讨论(0)
提交回复
热议问题