Using too many include(); poses any problem????

Discussion in 'PHP' started by smart, Jan 12, 2008.

  1. #1
    Hi all,
    I have a doubt whether using the function include(); 5 or 6 times in a PHP page for inserting the code poses any problem??

    Please suggest me with all your experiances.......


    Thank you in advance
     
    smart, Jan 12, 2008 IP
  2. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would use include_once() rather than include() saves issues if you include a page more than once.
    But 5/6 times is ok. You wont see any slowdown.
     
    lfhost, Jan 12, 2008 IP
  3. smart

    smart Active Member

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    I mean not the same file in all the include(); Different files.
     
    smart, Jan 12, 2008 IP
  4. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Including 5-6 files is not going to be an issue if they are local. If you were doing includes that were url based it may be an issue but for local files which have code it's not an issue.
     
    InFloW, Jan 12, 2008 IP
  5. shedboy

    shedboy Peon

    Messages:
    63
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have created in the past a basic template which had 10 include() for ads, navigation bars, latest news, links and other features on a website and there were no issues whatsoever
     
    shedboy, Jan 13, 2008 IP
  6. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #6
    I just use the basic <?php include"filelocation";?> I use that quite a bit on my sites, never had a problem with it. Doesn't slow my sites down in the slightest.
     
    scottlpool2003, Jan 13, 2008 IP
  7. smart

    smart Active Member

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Thank you very much for sharing your experiances
     
    smart, Jan 13, 2008 IP
  8. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you have a large system it can really slow things down.

    For instance I have a site that requires around 20 includes per page, the issue is you are going to the file system and parsing the file each time.

    To REALLY speed things up you can use APC. This will store all the compiled includes in memory far next time.
     
    tonybogs, Jan 13, 2008 IP
  9. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It depends on what the included files are doing and what type of file system is being used (e.g., NFS on shared hosts can be slow). If your code is reasonably optimized and the file system is decent, you won't have any problem.
     
    Gordaen, Jan 13, 2008 IP
  10. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    include()
    include_once()
    require()

    all are fine.. no problem as many times as you need...
     
    webexpert, Jan 14, 2008 IP
  11. smart

    smart Active Member

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #11
    Hi
    I am going to include just header, navigation, footer, ads, like that as many as 10 to 15 includes. So does that slow down the page loading....... . They dont have any functions. Just code.
     
    smart, Jan 14, 2008 IP
  12. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    will not slow down the page.. infact - its a good practise to use includes.. because if you want any changes laters, you dont have to modify all the pages, you will just modify one page that will effect all the pages :)
     
    webexpert, Jan 14, 2008 IP
  13. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #13
    Just be careful not to get yourself into a loop. But as everyone's said already, multiple includes are never a problem, as all PHP really does is file_get_contents() the code and eval() it. You could try Op(eration)Code caching if its needed.
     
    jayshah, Jan 14, 2008 IP
  14. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #14
    I did an experiment before and the more includes you use, the speed of your script decreases. The decrease can be negligible though. But if you're meticulous with speed, you might have to put this into consideration.
     
    rkquest, Jan 14, 2008 IP
  15. LimeBlast

    LimeBlast Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I used this function more then 6 times in a page and still works well!
     
    LimeBlast, Mar 23, 2008 IP
  16. lawrenz

    lawrenz Peon

    Messages:
    246
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    include the file you needed on top.. not on very call of the script.. :)
     
    lawrenz, Mar 24, 2008 IP