I’ve been working on tutorialtastic over the past two days because creating the page, writing the page, uploading the page, etc can get incredibly tedious — in fact it puts me off publishing tutorials in the first place (some of you see this as a good thing, you can shut up :p).
Anyway, the scripting stuff that controls this (main) site connects to the MySQL database at the start of the configuration file and therefore theoretically connects to the database on every page (because the config file is included on every page) even when a connection is not needed (80% of my pages). Although this site is never going to get to the point where it’s exceeding its available resources (rock on site5.com) I do think that if I make my code more efficient it’ll benefit me anyway: if nothing else but to educate me further.
So.. instead of just sticking a ton of code on every page where I want something pulling from the database I’ve put the appropriate code into various functions (
fetch_categories() etc). This way, the code is only on one page so repeated stuff can just be called with one line instead of 30+ each time. Also, I’m using
mysql_close(); at the end of the function when the hard work is done, although as I’m not using persistant connections I don’t know if this is of any benefit…?
What I’m after is a yes/no from anyone as to whether or not I’m on the right track in terms of increasing efficiency and perhaps some suggestions from any geek-geniuses too. :)