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?
Each PHP file uses around 10 includes. So for every page that is displayed, the server needs to fetch 10 files, in addition to the rest of its functions (MySQL, etc).
Yes it will slowdown if you are including the script from other servers.
If the file is included twice, PHP will raise a fatal error because the functions were already declared. It is recommended to use include_once instead of checking if the file was already included and conditionally return inside the included file.
But as for execution speed, it has no influence, because they are just ignored by the interpreter. So basically, it does not matter if you add comments.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With