Includes Eating Up Resources?!

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
mgilsbach
Forum Newbie
Posts: 4
Joined: Thu Mar 02, 2006 12:53 pm

Includes Eating Up Resources?!

Post 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
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Includes Eating Up Resources?!

Post 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');
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
shoebappa
Forum Contributor
Posts: 158
Joined: Mon Jul 11, 2005 9:14 pm
Location: Norfolk, VA

Post 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://...
mgilsbach
Forum Newbie
Posts: 4
Joined: Thu Mar 02, 2006 12:53 pm

Post 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
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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:
Post Reply