Web Design Forum: Reducing database usage - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Reducing database usage Rate Topic: -----

#1 User is offline   dt17 

  • Advanced Member
  • PipPipPip
  • View gallery
  • Group: Members
  • Posts: 450
  • Joined: 22-May 09
  • Reputation: 14
  • Gender:Male
  • Location:Scotland
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 17 March 2010 - 12:44 PM

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!
0

#2 User is offline   EagleFreelance 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 46
  • Joined: 30-June 09
  • Reputation: 0
  • Gender:Male
  • Location:Shropshire
  • Experience:Advanced
  • Area of Expertise:Web Developer

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 ?
0

#3 User is offline   dt17 

  • Advanced Member
  • PipPipPip
  • View gallery
  • Group: Members
  • Posts: 450
  • Joined: 22-May 09
  • Reputation: 14
  • Gender:Male
  • Location:Scotland
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 17 March 2010 - 03:10 PM

View PostEagleFreelance, 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 ?


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.
0

#4 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,814
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 17 March 2010 - 04:46 PM

View Postdt17, 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.


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
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users