Headers and Output Buffering

I have a website laid out so that every page is actually an include on a main index page.
Would it be unwise to call ‘ob_start’ at the beginning of the index page and ‘ob_end_flush’ at the end in order to allow the page includes to call headers?
For example, would it cause my server’s resources to be eaten up, or cause pages to load slower for the client?

It’s going to use a bit of memory, but most html pages are pretty small, so I wouldn’t worry about that unless some of the pages are really huge. You can choose to only buffer in chunks, I think theres a default of 4096 bytes in php.ini or something like that, but you can set it. For your purposes, you probably only need to buffer the first so many bytes(enough to cover the first part of the html, probably up to your page header area or whatever). You included “page” file is probably going to figure out pretty quick whether or not it needs to send http headers, before it outputs the majority of the html.

There’s an advantage to getting the html head out to the client asap. You’re going to have external css file links there, and maybe some js too. Sooner you can get these out to the browser, the sooner it can start downloading them, even if it still needs to wait for the rest of the html.

Keep in mind there’s a small window of buffering anyway if you’re compressing output with gzip/deflate. And the webserver may buffer in a certain size window too(or maybe even the entire thing).

Basically, you don’t need to buffer the entire thing. You probably get away with buffering only a little bit.

I’d say it will be unwise, but not because resources or slowness.
Whole paradigm is wrong here. Including pages into main page is just worst way to make a site.
Other pages can be called using index pages, it is ok.
But not for direct include. Index page should start output only after included page is done working. So, use some template system and you’ll never have any header problem.

http://wallpapercommand.com/
I just started on this site about a week ago. It uses the “include” layout I was talking about, so each page looks the same on the top and bottom; only different in the middle.

You say using includes is the worst way to make a site, but it has been working pretty well for me so far. Is there a more efficient way to layout a site where only the middle area needs to change with each page?

I just have to disagree with you here. Ok let me back up, it sort of seems as if you’re contradicting yourself a bit. You say to use a template system but then you say to not use an index page to load those templates. So that’s confusing to me. And let me assure you, there are a TON of worse ways to create a site IMO…

Using multiple directories and a controller to load different templates is an ideal way to create a data-driven website, or even a website that is only partially data-driven. This structure creates permalinks of sorts to main directories of a site:

mysite.com/aboutme
mysite.com/myportfolio
mysite.com/contactme

In addition, this format obscures the technology used to create the site as well. A user doesn’t have to bother having to remember if the extension is .htm, .html, .php, .asp, .aspx, etc.

I suppose I could go on about this but I’m hoping I simply misunderstood you because I’m all about using a controller to load certain templates.

Yes. I just didn’t say that.
I said index should not start output before uncluded page done working.

Hey Morthian.
As I said above, you need some template system.
Your pages should not output directly to browser, but create array of data. Which can be passed to a template system.
So, frankly, each your page must be divided into 2 parts: “engine part” and “template part”.
And it might look like this:
<?
$title=“1st page title”;
$content= “some content”;

include “1st-page.tpl.php”;
?>
page’s template may use include operator to include common parts of HTML code.
So, index page become unnecessary. But still can be used though.