Welcome to WebmasterWorld Guest from 54.163.40.152

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multiple include files vs one big include

Efficiency?

     

madmatt69

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

WebmasterWorld Senior Member 10+ Year Member



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?

ahmedtheking

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

WebmasterWorld Senior Member 10+ Year Member



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!

darrenG

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

5+ Year Member



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.

PHP_Chimp

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

WebmasterWorld Senior Member 5+ Year Member



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]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month