1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Slow PHP include when reaching back a directory

Discussion in 'PHP' started by StoneHenge, Mar 25, 2005.

  1. #1
    Hello everyone,

    I've run into something strange with my site, and I'm desperate for help. Four hours of google searches and multiple attempts at re-coding haven't amounted to much. I'm hoping you guys might be able to shed some light on this. Here's the problem:

    My site uses a lot of headers, footers, etc, all retrieved with 'include'.

    Suddenly, two days ago, all pages with headers became really slow. We're talking 4-6 seconds to load a page.

    I've isolated the problem to this: when the include command has to reach back in the file system to retrieve the file, it is slow. So this page:

    /pages/index.php

    If it loads a header in pages/headers/header.php, it's fast.
    If it loads a header in headers/header.php, it's slow. And it's slow if I use an absolute address: http://domain.com/headers/header.php, a relative address like ../headers/header.php, or the server address: /home/user/public_html/headers/header.php

    Just any time it has to reach back for anything it becomes increasingly slow. My hosting people haven't been able to figure it out, or tell me what they changed in the last 48 hours to cause this.

    Have any of you seen this before? Any suggestions? I'd really rather avoid having to put the header/footer files in every folder on my site.

    THANKS for any and all replies to this. I really appreciate it.

    -Kent
     
    StoneHenge, Mar 25, 2005 IP
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try some alternative include method, just to see if it has anything to do with include. For example use readfile or even SSI statement:

    <!--#include file="filename.ext" -->
    <!--#include virtual="/includes/filename.ext" -->

    J.D.
     
    J.D., Mar 25, 2005 IP
  3. StoneHenge

    StoneHenge Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi J.D.,

    Until this morning, everything was done using 'readfile'. The web host suggested I try 'include' instead, but it didn't help.

    I tried SSI like you suggested (and they claim I can use SSI), but it didn't work. The shtml file came back: [an error occurred while processing this directive]

    Maybe they have to manually configure me account to use SSI? Of course everyone seems to be off for the weekend, so I'm stuck.
     
    StoneHenge, Mar 25, 2005 IP
  4. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Make sure you don't have spaces between <!-- and #.

    See how long a single include takes (see a sample in http://ca.php.net/manual/en/function.microtime.php).

    J.D.
     
    J.D., Mar 25, 2005 IP