View Full Version : Lowering load time

09-13-2003, 06:28 PM
I have a php script on my site that makes the site load really slow, i'm trying to see if there's anyway it could be faster. He's part of the script....

if($tsr == "aboutdb"){$information = "About the Series";}
elseif($tsr == "aboutstaff"){$information = "About the Staff";}
elseif($tsr == "af"){$information = "About Dragonball AF";}
elseif($tsr == "afterlife"){$information = "The Afterlife";}
elseif($tsr == "aim"){$information = "AIM Buddy Icons";}
elseif($tsr == "akira"){$information = "Akira Toriyama";}
elseif($tsr == "androids"){$information = "The Androids";}
elseif($tsr == "animated"){$information = "Animated Gifs";}
else {$information = "content";}

i have around 250 elseif statements, which is why i'm thinkin the site loads so slow. Is there anyway to do what i want, but faster like if i only use if statements or something?

09-13-2003, 08:51 PM
250 elseif statements? :eek:
That's close to unmaintainable. I doubt though they really slow down your page, unless they're called in loop or something.

But anyway, here's a different approach that cuts some lines:

$titles = array(
"aboutdb" => "About the Series",
"aboutstaff" => "About the Staff", // etc.

if (isset($titles[$tsr])) {
$information = $titles[$tsr];
} else {
$information = "content";

All you need to do is populate the $titles array. You could even store the data in a file or in a database and fetch the $titles array contents from there.

09-13-2003, 09:02 PM
Looks like you should better use 'switch'


or use an array or so. For instance, store these values like "About the Series" in an array and use an index instead of "aboutdb ". So use an integer instead of some cryprical stringvalue
Then you could have somenthin like


If your array would look like
"0" => "About the Series"
"1" => "About the staff"

and $str = 1 then

$information = $array[$tsr]

would instantly set the rigth value for $information

<edit> posts crossed. mordreds code will be more transparent to maintain. </edit>

09-13-2003, 09:06 PM
I was already writing a reply about maintainability issues with your suggestion, raf.... ;)

09-13-2003, 09:27 PM
i know my own weaknesses. (Thats why most of my code is completely idiots-proof :D )

I kinda felt it wasn't the best way but i'm so used to working with databases and using primary key values, that i'm drawn to using indexes ...

09-13-2003, 11:17 PM
well how i get $tsr is i link all my pages "index.php?$tsr=stuff" and then, i just include "$tsr.html" so i really cant have $tsr as a number.

I know the site loads pretty fast in a highspeed connetion but i noticed it loaded a little slow with my 56k connection, and i have it catched too. It usually takes like 5-10 seconds to load it, but if it shouldn't take too long, maybe it might be my computer :confused:

09-14-2003, 12:58 AM
mordreds code should work.

I don't think the connectionspeed has an influence on the processingtime for your script. So it's probably something else (like loading images or so) that takes up the responsetime.

09-14-2003, 01:00 AM
URL: http://tsr-corp.com/
Date Tested: Saturday, Sep 13, 17:53 EDT
Page Rating:
Rating Criteria: Standard
Total Page Size: 143168 bytes
Total Graphics: 115046 bytes - 27 images
Server Connections: 5

It's the graphics that is taking alot of the time
Don't know if the link will work for long or not but