How to speed up a page with >100 mysql queries?

mysql, optimization, php, sql

Solution

There are a number of options for MySQL.

First is to setup a Query Cache in your MySQL config. If your program is `SELECT` heavy, try setting `low-priority-updates` to on. This gives higher priority on the server to SELECT statements, and less priority to INSERT/DELETE/UPDATE statements.

Changing MySQL's use of memory might be a good idea, especially if you use a lot of `JOIN` statements - I usually set the `join_buffer_size` to about 8M.

From a PHP point-of-view, try caching results.

Edit: the class down the forum page that Suresh Kamrushi posted is a nice way of caching in PHP.

Problem

I have a PHP page on my website, that uses over 100 mysql queries. All the queries are different, and are all just `SELECT` queries from multiple tables. On average, the page takes about 5 seconds to load, and I wish to improve this time. What method of optimization do I have? I did some research, and took a look into memcache (I don't know how it works, what it can do or if it applies to my situation, so help may be appreciated), but as I said, I don't know if that is applicable to my situation. I was also thinking of a query caching program, but don't know of any I can use? Any help?

Original source

Related problems