Just need your opinions guys, I'm in the process of implementing a new feature to my CMS which will effectively require a database request everytime a page with the feature is present, is loaded.
I was just wondering if anyone knew any way to avoid accessing the database everytime - perhaps a method of caching?
It doesn't seem like much, but say 100 users hit my page, that's alot of additional database requests that I would like to avoid if possible.
Thanks in advance!
Page 1 of 1
Reducing database usage
#2
Posted 17 March 2010 - 01:27 PM
First of all I wouldn't worry about it as it wont affect page loading speed ( unless you have a massive data and crappy database ).
Otherwise you can use Sessions.
What data is coming from the database ?
Otherwise you can use Sessions.
What data is coming from the database ?
#3
Posted 17 March 2010 - 03:10 PM
EagleFreelance, on 17 March 2010 - 01:27 PM, said:
First of all I wouldn't worry about it as it wont affect page loading speed ( unless you have a massive data and crappy database ).
Otherwise you can use Sessions.
What data is coming from the database ?
Otherwise you can use Sessions.
What data is coming from the database ?
I can't use Sessions as it's going to be user content entered via the CMS which will be pulled, "labels" of text if you like so users can, for example, change there form labels without having to worry about affecting any of the form code.
So if I have 10 form labels, each read from a database, it's essentially 10 db requests.
This is just an example, it can be used for other things such as snippets of text on dynamically generated pages that the client would otherwise not have access to change.
#4
Posted 17 March 2010 - 04:46 PM
dt17, on 17 March 2010 - 03:10 PM, said:
I can't use Sessions as it's going to be user content entered via the CMS which will be pulled, "labels" of text if you like so users can, for example, change there form labels without having to worry about affecting any of the form code.
So if I have 10 form labels, each read from a database, it's essentially 10 db requests.
This is just an example, it can be used for other things such as snippets of text on dynamically generated pages that the client would otherwise not have access to change.
So if I have 10 form labels, each read from a database, it's essentially 10 db requests.
This is just an example, it can be used for other things such as snippets of text on dynamically generated pages that the client would otherwise not have access to change.
If you're using PDO you can create a globalo instance of your database. This tends to speed up sites where lots of queries are going on. E.g. this speeded up my ecommerce store hugely.
You could also try more effecient queries E.g. fetching a range of labels back as an array, instead of 10 different queries.
For things like paging sessions can be used to speed things up. E.g. for paging you'll at some point need to know the total number of records. You could do something like:
if (!$_SESSION['maxPages']) {
//code to get num pages from db
} else {
set pages from session variable
}
Share this topic:
Page 1 of 1
Help

















