How long do includes take?

Discussion in 'PHP' started by CygnetGames, Jun 19, 2007.

  1. #1
    I'm new to PHP and trying to make my website as fast as possible.

    Is there any real difference in speed between including, say, an 8K file rather than a 50k file?

    I'm precalculating database queries and wondering if I should save the results of each query in a separate file or whether they would be ok all in the same file.
     
    CygnetGames, Jun 19, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    No, the script is not downloading the pages, it is being done on the server and accessing files on the local filesystem is quick enough that the difference in cases like your one will be negligible.

    As for what you are trying to do, I would suggest separate files to save processing when parsing through the larger file to get the data needed.
     
    krt, Jun 19, 2007 IP
  3. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just to add to what krt said there is some overhead when doing includes opposed to having the code already there. Now is the overhead noticable? No not in most people's cases. You'll start to notice it when you're including 50 files on one page.
     
    InFloW, Jun 19, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    blink your eyes one time. that took more time than it would to parse the includes in most scenarios.
     
    ansi, Jun 19, 2007 IP
  5. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #5
    True but these things matter when you have a lot of visitors. The resources taken by those includes start to actually matter.
     
    InFloW, Jun 19, 2007 IP
  6. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #6
    sure. if you're using a 400mhz pentium II as a web server.
     
    ansi, Jun 19, 2007 IP
  7. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I receive 1,000,000 visitors a day I do 50 includes opposed to 1. I will require more server resources if I'm doing the 50 includes. And it will not be a marginal difference it will be several servers more depending on specs.

    If you scale it enough these things do matter
     
    InFloW, Jun 19, 2007 IP
  8. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #8
    If you can avoid using include_once / require_once, it will also save a little time.

    Most of the time all of this is going to be completely negligible. The time that it takes for the information to get from your server to your visitor's browser is where most of the wait comes into play. If you can keep the amount of data you are sending during a request as low as possible it will have a more noticeable effect on speed. Additionally, if you are able to use caching you can save some server resources as well.
     
    jestep, Jun 19, 2007 IP
  9. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #9
    it's highly unlikely that he's getting a million visits a day. and if you had read what i wrote, you would notice that it says "in most scenarios".
     
    ansi, Jun 19, 2007 IP
  10. CygnetGames

    CygnetGames Peon

    Messages:
    43
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ok, thanks for your help guys.
    I've already got the system in place to use separate files, so i'll stick with that - was just curious as to how much strain it puts on the server. It makes sense that the most important thing is how much data you're sending to the client, not how much you read from the local filesystem.
    I've only got at most 2 database includes (about 8K each) on any one page, and a couple of tiny includes for templating, so I think I should be fine.
     
    CygnetGames, Jun 19, 2007 IP
  11. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #11
    You would be using an advanced caching solution for both the server side scripting and probably for the output too if you had that many visitors so that is out of the question.

    The point is that if it is more convenient to use more include files, go ahead :)
     
    krt, Jun 19, 2007 IP