jeromepelletier
05-16-2006, 12:03 PM
Alright ill explain and go through some things first, what i need to do is lower my CPU usage on my site, im not exactly sure what to do, ive read through things on the web but its still unclear, also id like to improve load time saying, might as well go for a 2-in-one!
First of all, when selecting something from my database, i use:
$firstvar="SELECT * from database where something='$something'";
$firstvar2=mysql_query($firstvar) or die(mysql_error());
$firstvar3=mysql_fetch_array($firstvar2);
My first question is, do you recommend a better way to do this? I noticed in some other peopels sites, they use a shorter or almost completely different way. Secondly about the above, the "Select * from" do you recommend selecting only what i need? Sometimes im oinly getting 10 things, somethings more or less. Thirdly, i dont have anything indexed, should/how do i do that, ive read about it but it just doesnt make sense...I use the above many many times in my scripts, if there is a way to improve them, i think my codes would be a lil bit better.
When updating the database I use
$varupdate="update database set thing=123 where ID='$thingsID'";
mysql_query($varupdate) or die(mysql_error());
About the above code, again, is there a better and faster way of doing so? (by fast a mean load the page faster and by better i mean make the CPU usage less heavy)
Now that i got the database thing down, onto the actual code!
Things I dont do in my code:
1) Using a footer & header
2) Caching
3) 1 and 2 are all i can think of....
For headers and footers, are they better? As in run faster and not so bad on CPU usage? I should explain my code a bit I guess ... What I do i have 1 main file, then when another is needed, such as someone clicks maybe Buy This, then the file buythis.php is called up using include 'fileexample.php' in the main file. IF a header and footer is better then what im using, and is highly recommended, im guessing thats another thing to do.
For caching, i just recently saw this online in a site, something about opcode and such that can speed the site up by 200%, is this true?
Some other things are, i do have a image background, i do have image borders for my tables, theres a semi amount of text (mainly the chat is the killer for text)
SO, what do you guys think i should do?
First of all, when selecting something from my database, i use:
$firstvar="SELECT * from database where something='$something'";
$firstvar2=mysql_query($firstvar) or die(mysql_error());
$firstvar3=mysql_fetch_array($firstvar2);
My first question is, do you recommend a better way to do this? I noticed in some other peopels sites, they use a shorter or almost completely different way. Secondly about the above, the "Select * from" do you recommend selecting only what i need? Sometimes im oinly getting 10 things, somethings more or less. Thirdly, i dont have anything indexed, should/how do i do that, ive read about it but it just doesnt make sense...I use the above many many times in my scripts, if there is a way to improve them, i think my codes would be a lil bit better.
When updating the database I use
$varupdate="update database set thing=123 where ID='$thingsID'";
mysql_query($varupdate) or die(mysql_error());
About the above code, again, is there a better and faster way of doing so? (by fast a mean load the page faster and by better i mean make the CPU usage less heavy)
Now that i got the database thing down, onto the actual code!
Things I dont do in my code:
1) Using a footer & header
2) Caching
3) 1 and 2 are all i can think of....
For headers and footers, are they better? As in run faster and not so bad on CPU usage? I should explain my code a bit I guess ... What I do i have 1 main file, then when another is needed, such as someone clicks maybe Buy This, then the file buythis.php is called up using include 'fileexample.php' in the main file. IF a header and footer is better then what im using, and is highly recommended, im guessing thats another thing to do.
For caching, i just recently saw this online in a site, something about opcode and such that can speed the site up by 200%, is this true?
Some other things are, i do have a image background, i do have image borders for my tables, theres a semi amount of text (mainly the chat is the killer for text)
SO, what do you guys think i should do?