It is very common to use include files. I think it is overused to keep the codes tidy without considering performance. For several includes, disk should read the files, and as we extremely use disk, it can be a slow process. However, this is not the main slow process or the rate-limiting process, as loading the file with file_get_contents is few times faster.
I think this is the reason that major websites put javascripts within the html file rather than loading them by file. Alternatively, it can be a good idea to split a large JS file into several small JS files, as parallel http requests can load the entire JS codes faster. But this is different from php files, as php script reads include files one by one during the process.
-
Please comment how much serious this problem can be? Imagine a webpage is loaded in 0.60s, can
includeof 10 php files turn it to 0.70s? -
Although this effect should be negligible, I want to know if there are approaches to speed up this process. I do not mean php caching like
APC.
P.S. This question is not for practical application (a typical case), but theoretical considerations in general.
includeand its ilk is a necessity. It is similar toimportin Java and python in that it is used for class and function definitions.includeshould be extremely fast, but using it will delay script execution compared to if it was not there.includeis totally different fromfile_get_contents(). The latter is a function rather than a construct and returns a string.includewill actually execute the code of the included file.Your statement about splitting JS files is incorrect as script downloads from the same domain block parallel downloads and it’s generally recommended to have as few includes as possible in general.
I highly doubt that having multiple
includes, assuming all are necessary, is going to slow down the performance of your page. If you are having performance problems, look elsewhere.If you want to speed up php, look into using a php compiler.