Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multiple include files vs one big include


7:37 pm on Nov 8, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 28, 2001
posts: 779
votes: 0

Hey all,

Right now on my site I call 2 includes - a header.php and a footer.php.

A friend of mine suggested putting the code from both of those includes into one file, say 'includes.php' and then in my templates calling the code from the include as a variable.

Example, echo $header; and then echo $footer; in the appropriate places.

He said this would be more efficient because then the server only has to reference one file instead of two, even though the new includes.php file is bigger in file size.

I'm just wondering some of your opinions on this? Is it really more efficient?

8:02 pm on Nov 8, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts: 789
votes: 0

Well it all depends. Serving one file is always faster and in this case, it works fine for you. However, if you where to have a folder of function files, it would reduce performance by loading all of them instead of loading the ones you need when you need them. What you've got to remember is that the impact may just be milliseconds and you may not even notice!
8:47 pm on Nov 8, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 19, 2006
votes: 0

All I would add to that is, if you know that you will always need both files, then they are better off as one file. the size of the file isnt relevant, because the two files would take up just as much memory as if they were just one file.
8:49 pm on Nov 8, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 12, 2007
votes: 0

Could you use the auto_append_file [php.net] and auto_prepend_file, so that you dont need to worry about adding the code to each page manually?

This auto version treats the code as if it is required, so will produce fatal errors.
It will also call each file individually, however if this is a question about time taken to manually code then this may be a solution.
However some servers dont allow you to specify php directives in the htaccess file...so this may not work for you anyway, but could be worth a try.

[edited by: PHP_Chimp at 8:50 pm (utc) on Nov. 8, 2007]


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members