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
Includes Eating Up Resources?!
Moderator: General Moderators
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
The HTTP wrapper will slow things down a bit, try using an absolute disk address (if you can?).For the sake of simplicity my include line uses an absolute path (i.e. http://www....)
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.My pages are all HTM pages being processed as PHP pages.
... and welcome to phpDN!
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Includes Eating Up Resources?!
I can't imagine that PHP is causing much load at all for just includes unless it is not configured properly.
That is probably your problem. it should just be:mgilsbach wrote:1. For the sake of simplicity my include line uses an absolute path (i.e. http://www....)
Code: Select all
include('path/to/file.html');(#10850)
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
From Manual: http://www.php.net/include
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://...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
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.
Thanks again.
-Mike
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.
Thanks again.
-Mike
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
You still have the option of going pure HTML too. (You got the time now too.) Keeping it simple has it's advantages.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.