A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearIn PHP, how many DB calls per page is okay? - page 1
User InfoPosts
In PHP, how many DB calls per page is okay?#1
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.

posted date: 2008-12-16 04:16:00

Re: In PHP, how many DB calls per page is okay?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-16 04:16:01

Re: In PHP, how many DB calls per page is okay?#3
I'm tempted to close that as "subjective and argumentative". What's the point of the question?

posted date: 2008-12-16 04:19:00

Re: In PHP, how many DB calls per page is okay?#4
I think your current number of queries is okay as long as the servers (web and database) can handle all your requests and return a page in a acceptable time. It depends on the servers to a large scale.Nevertheless using as few queries as possible is a good rule anyways.

posted date: 2008-12-16 04:21:00

Re: In PHP, how many DB calls per page is okay?#5
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.

posted date: 2008-12-16 04:22:00

Re: In PHP, how many DB calls per page is okay?#6
One or less is always best. Two is usually one too many. If you can return multiple result sets in a single query, then do it. If the information is fairly static, then cache it and pull from cache. 10 separate database calls is not good, but its not going to kill a low usage site.

posted date: 2008-12-16 04:57:00

Re: In PHP, how many DB calls per page is okay?#7
Nowhere is the number actually given. It depends on the way the servers are used more than the servers horsepower.

posted date: 2008-12-16 04:59:00

Re: In PHP, how many DB calls per page is okay?#8
When I worked on the www.boxman.com project in the .com boom, they had one website that appeared as 9 different language/country sites under different domains. Every piece of text was pulled from the DB as well as usual things like products etc... Each page typically would involve 200 odd DB requests, but mainly returning a single id,string combo. We had 100 of users on the system at a time.The DB ran DB2 SQL on a 16 way RS6000 unix box. This is probably equivient to a modern day 3ghz QUAD core intel box.The system worked... as volumes picked up I implemented a cache which involved writing a sync process that moved data that was static on a daily basis to the webserver's drive so it no longer hit the DB.Basically I would say if performance is okay then it's okay! but you should allow for expanding demand and be ready for it when it happens.

posted date: 2008-12-16 05:04:00

Re: In PHP, how many DB calls per page is okay?#9
This is a perfectly valid question.

posted date: 2008-12-16 05:07:00

Re: In PHP, how many DB calls per page is okay?#10
Another important matter except for caching is to use prepared statements. When you execute a query, the db has to 1) analyze the query and 2) execute it. If you use prepared statements, the db can cache the query plan it used last time, so each query will be a smaller burden on the dbms. Don't count the load in how many queries you execute, but how much stress you put on the dbms. Executing 100 prepared queries can be faster than executing 50 queries generated ad-hoc in the code.

posted date: 2008-12-16 05:23:00

Re: In PHP, how many DB calls per page is okay?#11
I don't think this would make the slightest difference in this case - analysing the queries is probably not the problem. I rather suspect that it's round-trips to the database, the queries themselves are probably rather easy

posted date: 2008-12-16 05:36:00

Re: In PHP, how many DB calls per page is okay?#12
Don't forgetuse stored procs - they run faster.run them in fresh - once a week. (the database optimizes stored procs using its current state. If this changes then the store process will stop being optimial).use commands like "show plan" to really understand what your SPs are doing.Stored procs can return multiple datasets (datatables) this cuts down on network traffic. A single stored proc can do multiple things.Tony

posted date: 2008-12-16 07:48:00

select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.