Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PHP, how many DB calls per page is okay?

I've got shared hosting on a LAMP set up. Obviously the fewer calls to the Db per page the better. But how many is too many? Two? Ten? A hundred? Curious what people think.

like image 462
Corey Avatar asked Dec 16 '08 12:12

Corey


2 Answers

That really depends on your (db)servers setup. Try to cache most of information as possible and reduce db calls to a minimum. A database will (almost in every case) be the bottleneck of your service - the higher the usage of your site. So whatever you do try to avoid fireing a query as if not really necessary.

I try not to use more than 10 db calls per page, but that really depends on your infrastructure and the information you want to provide.

like image 131
smartcoder Avatar answered Oct 19 '22 03:10

smartcoder


I would say that depends on the server load. If you have 1 visitor per minute, then 1-10 db calls per page would be just fine. If your server load is higher than that, say 10 page requests per second, then you should consider caching to minimize the load on your db server.

like image 44
Marcus Avatar answered Oct 19 '22 04:10

Marcus