views:

195

answers:

3

What are the advantages/disadvantages of using include/require's to achieve a singular file that contains multiple pages as opposed to directing the user to many individual pages and storing the variables as session variables?

In particular I am asking with regard to a long multi step process (think questionnaire).

+1  A: 

If you're including the code of very single page to render one of them:

  1. You're loading and parsing tons of code that you're not going to use for every request
  2. Any parse error introduced into any one of those files will cause your whole site to come down

The first PHP app I inherited used the "include everything" strategy. There was an immediate, obvious performance gain when I transitioned it to only loading code that was actually going to be used.

Frank Farmer
A: 

Personally I love using includes and requires to construct your page.

The part where you draw the line is including everything.

Let's say I have a web app that let's people resize photos online, on the homepage I would include the header, a sidebar, the homepage content area, and a footer.

The main part to focus on here is the homepage content area, if they were on the homepage there would be no point to include or require the file that handles the functions for resizing images.

If you would like a real world example of includes and requires and how effective they are, check out any Wordpress blog. I have a few clients that have wanted to use Wordpress as a CMS and to this day they still function superbly even with tons of data and user flowing through them.

Also, this subject has been covered multiple times, feel free to check out: http://stackoverflow.com/questions/786929/one-large-include-file-or-several-smaller-ones

Hope this helps.

David
A: 

You might get better answers if you could be more specific about what particular technical concerns you have about the two approaches or what you are looking for.

Choosing one approach over the other is much more related to interaction design than about PHP. Check this Web Pattern Library. You usually use a Wizard or multi-paged form when

the user wants to achieve a single goal but several decisions need to be made before the goal can be achieved completely, which may not be known to the user.

A multipage questionnaire that collects pages in topics and presents them to the user on page by page basis might be helpful for them to better focus on the topic at hand.

Apart from that, splitting the page might yield benefits in transfer and rendering times, but unless you are sending a 2MB questionnaire, this is hardly an issue if you use HTTP compression. If there is no PHP in the included files you might also just fpassthru them, so PHP does not need to parse the files.

Gordon