Possible Duplicate:
Efficiency for including files of functions (in PHP)
Using too much include() in php
If so, what would be the recommended amount of files to include at most?
Possible Duplicate:
Efficiency for including files of functions (in PHP)
Using too much include() in php
If so, what would be the recommended amount of files to include at most?
Including a file will do the following things:
Both of these operations take time. Not much time, but even so it can add up if you have a lot of includes, so the basic answer to your question is 'yes, it can affect performance'.
However, the size of that performance hit is pretty tiny, and is far outweighed by the advantages of writing good quality well structured code (which includes keeping separate classes/functionality in separate files).
Truth be told, if you're worried about the performance of these sorts of things, try running your code through a profiler such as xDebug. This will show you exactly what parts of your code are taking the most amount of time. include()
statements will show up in there, but are very unlikely to be anywhere near the top of the list.
Unless you're writing a site with visitor numbers like Facebook, then you're unlikely to need to worry about the performance of include()
. But take a look at the profiler output from xDebug, because there are likely to be other things in your code that are going much slower than you expected, or are being called to often, or are looping too many times, etc, and fixing these will have a big impact on the performance of your code.
The include directive does "paste" the contents of the included file at the very same spot where it stands. So the included code adds up to the actual script. Here's a good explanation PHP include(): File size & performance - the accepted answer.