Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lowering load time

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

    PHP Code:
    <?php
    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?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    250 elseif statements?
    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:

    PHP Code:
    $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.
    De gustibus non est disputandum.

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Looks like you should better use 'switch'

    http://be.php.net/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

    $array[$tsr]

    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>

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was already writing a reply about maintainability issues with your suggestion, raf....
    De gustibus non est disputandum.

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i know my own weaknesses. (Thats why most of my code is completely idiots-proof )

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

  • #6
    New Coder
    Join Date
    Aug 2003
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    http://r.netmechanic.com/toolbox/loa...&s=NetMechanic


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •