Php – How many MySQL queries should I limit theself to on a page? PHP / MySQL


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 information from. Here are some sample different queries for this one page:

  • article content and info
  • IF the author is a registered user, their info
  • UPDATE the article's view counter
  • retrieve comments on the article
  • retrieve information for the authors of the comments
  • if the reader of the article is signed in, query for info on them
  • etc…

I know these are basically going to be pretty lightning quick, and that I could combine some; but I wanted to make sure that this isn't abnormal?

How many fairly normal and un-heavy queries would you limit yourself to on a page?

Best Solution

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.