which is faster: query database or include

Discussion in 'PHP' started by bobocheez, Nov 6, 2009.

  1. #1
    So, I have some code and am wondering what would make my site faster, loading it from the database, or just adding an include function....
     
    bobocheez, Nov 6, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    include would probably be faster. does it have any php code to parse or just plain text?
     
    JAY6390, Nov 6, 2009 IP
  3. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    it has code
     
    bobocheez, Nov 6, 2009 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    what is the nature of the content? dynamic or once written is gonna be same way forever?
    how frequent new content come?
    at what frequency would you need to change it? and does it have to be done by someone not knowing php?

    above questions when answered properly, will give solution automatically :)
     
    mastermunj, Nov 6, 2009 IP
  5. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #5
    nature: javascript functions stored in php files
    dynamic: no, always same code in a specific file
    frequency of new content: n/a
    frequency of display: one file will display every 1 out of 10 times from a list of 10 files in a loop
    do i know php?: yes
     
    bobocheez, Nov 6, 2009 IP
  6. kbluhm

    kbluhm Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Benchmark it.
     
    kbluhm, Nov 6, 2009 IP
  7. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Yeah, do a simple benchmark test using microtime().

    Anyway I think include is faster?
     
    ads2help, Nov 6, 2009 IP
  8. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #8
    i would suggest include only, that since they are not gonna change frequently, store them as JS and get cached to reduce your data transfer resulting in faster page load :)
     
    mastermunj, Nov 7, 2009 IP
  9. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #9
    Include it is.
    Thanks people
     
    bobocheez, Nov 7, 2009 IP
  10. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #10
    code should never be stored in a database.
     
    killaklown, Nov 7, 2009 IP
  11. kbluhm

    kbluhm Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I think (hope) the OP's asking whether he should store info in an array rather than fetching it from the database.
     
    kbluhm, Nov 7, 2009 IP
  12. nihcer

    nihcer Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #12
    I disagree. I use a database to store Smarty templates and PHP code (smarty resource) and it works great.
     
    nihcer, Nov 7, 2009 IP
  13. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #13
    @kbluhm - basically
    @killaklown - unless you have over 1000 embedded videos that sometimes have to be changed, although I agree that large static code should not since it wastes more bandwidth
     
    bobocheez, Nov 7, 2009 IP
  14. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #14
    i dont get the 'unless you have over 1000 embedded videos that sometimes have to be changed'. The table should store url, width, height... shouldnt need to have the code for the embedded video in it... (unless im mis-understanding what your saying)


    @nihcer, im not saying its wouldnt work, databases are meant to store.. data... not source code. Sure you can, but its not suggested that you do.
     
    killaklown, Nov 7, 2009 IP
  15. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #15
    I think you are misunderstanding me killaklown. Picture this: a movie site with embedded videos from megavideo, youtube, veoh, and zshare. Now, each one has its own style of code. Like zshare - it uses an iframe, while youtube uses an object.

    My theory behind this is that it's more efficient if the entire embed code is stored in the database, instead of having a function for each site to get the URL, then get the video from the site.

    Or, how you're saying(if i understand correctly) that the table has a column for width, height, url, ect. This is fine, but very tedious, unless you have a script that picks out the variables from the embed code for each type of code.

    Therefore, you just copy and paste the code, and echo it onto the page...and voila, you have a motion picture. So, whenever the video goes missing (if it's deleted), then you just go use the video host's search engine to find the same video from another user.
     
    Last edited: Nov 7, 2009
    bobocheez, Nov 7, 2009 IP
  16. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #16
    I would think functions would work fine...

    (Pseudocode)
    
    if(video==youtube)
    embedYoutube(url,width,height);
    else if(video==zshare)
    emebedZshare(url,width,height);
    Code (markup):
    Much less traffic between application and database if you use functions.



    Sure, your way is a quick and easy way, and it achieves the same result... but a professional developer would never say to do it that way. (unless if they really dont care about moniterizing... which really wouldnt make them a professional then)


    Edit: also possible to copy & paste embedded code into a textbox, and have the php pull out the width/height/url
     
    killaklown, Nov 7, 2009 IP
  17. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #17
    hmm, looks like I better take notes lol

    quick question:

    I have a piece of code where, $n is a sequential number from 1-20, and $display is from the database with numbers 1-20, but in a random order.
    How can the following code be edited so that $display will equal $n?

    
    $n = 0;
    while ($n < 20) {
    $n++;
    
    $query_d = "SELECT display FROM hits_d WHERE id='$n' ORDER BY display DESC";
    $result_d = mysql_query($query_d) or die('Sorry, could not access the database');
    $row_d=mysql_fetch_array($result_d, MYSQL_BOTH);
    $display = $row_d['display'];
    
    $a = '$a'."$n";
    if ($display == $n) {$show = $a;}
    echo "n: $n display: $display show: $show<br/>";
    }
    PHP:
     
    bobocheez, Nov 7, 2009 IP