Page 1 of 1

Includes Eating Up Resources?!

Posted: Thu Mar 02, 2006 1:15 pm
by mgilsbach
Hi,

I have a site that is getting pounded with traffic. Basically, all of the available Apache processes are being taken up. I have already determined that it is not a DOS attack, but legitimate traffic.

My Hosting Provider thinks the problem is being exacerbated by my PHP includes. I am using includes on most of my pages for dropping in redundant navigation and header code. The includes themselves are straight HTML. Nothing fancy. Simple code reuse.

My host seems to think that these includes are using extra processes. For example, a page that calls for a header include and a navigation include is using three processes. A couple of variables that may or may not matter: 1. For the sake of simplicity my include line uses an absolute path (i.e. http://www....) 2. My pages are all HTM pages being processed as PHP pages.

I don't really want to have to copy that code into every page. Seems stupid.

Any thought?

Thanks,
Mike

Posted: Thu Mar 02, 2006 2:23 pm
by Buddha443556
For the sake of simplicity my include line uses an absolute path (i.e. http://www....)
The HTTP wrapper will slow things down a bit, try using an absolute disk address (if you can?).
My pages are all HTM pages being processed as PHP pages.
If all you are doing is including header, menu and footer then why not just generate HTML pages using PHP? HTML can take a significant traffic load even on a shared server but not if it's being precessed as PHP.

... and welcome to phpDN! :D

Re: Includes Eating Up Resources?!

Posted: Thu Mar 02, 2006 4:22 pm
by Christopher
I can't imagine that PHP is causing much load at all for just includes unless it is not configured properly.
mgilsbach wrote:1. For the sake of simplicity my include line uses an absolute path (i.e. http://www....)
That is probably your problem. it should just be:

Code: Select all

include('path/to/file.html');

Posted: Thu Mar 02, 2006 5:57 pm
by John Cartwright
You won't see any noticable difference from just a couple includes, unless if course these are pretty big files..

I usually end up including around 15-30 includes depending on requests.. and include speed isn't something I'm worried about

Posted: Thu Mar 02, 2006 6:35 pm
by shoebappa
If you include with the http:// it goes out and back through the webserver with the http wrapper.

From Manual: http://www.php.net/include
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper
Also if they're just html files your including, why parse them as PHP by using include or require? Use readfile(relativepath); which won't parse for PHP and should be a little faster. My money is on it making an http request for the file because you're using the http://... But readfile will save some to, but not if you use http://...

Posted: Fri Mar 03, 2006 9:08 am
by mgilsbach
Thanks for all of your advice.

It looks like changing the include paths from absolute (http://domain/includes...) to relative (../includes...) helped quite a bit.

The underlying problem is that the site is simply being crushed with traffic and needs a more robust hosting solution, but this seems to have at least mitigated the problem.

More to the point, it's eliminated my code as the source of the problem and put the onus back on the network admin. 8)

Thanks again.

-Mike

Posted: Fri Mar 03, 2006 11:44 am
by Buddha443556
mgilsbach wrote:The underlying problem is that the site is simply being crushed with traffic and needs a more robust hosting solution, but this seems to have at least mitigated the problem.
You still have the option of going pure HTML too. (You got the time now too.) Keeping it simple has it's advantages. :wink: