etrader Posted August 28, 2011 Share Posted August 28, 2011 We regularly use 'include file' to include general codes. But does it really identical to writing the code in the current php file? I mean does it take time to read an external file (comparing to the case that the code are simple writing in the processing file?). I am asking this question to know if there is a time difference between a single php file or include 20 external files (the same php code, just put on other files)? Quote Link to comment Share on other sites More sharing options...
freelance84 Posted August 28, 2011 Share Posted August 28, 2011 Including a script i found can speed up the execution of a script a little.... http://www.phpfreaks.com/forums/index.php?topic=321105.msg1515863#msg1515863 Including files can reduce the maintenance too as you only need to change one file (if of course the file is being used on more than one script) Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted August 28, 2011 Share Posted August 28, 2011 Put simply...does a bear shit in the woods? If you include alot files that are not needed this will increase page load time, it's best to put the important PHPs in a single file, and load that, than to load 10 different files that equivantly load the same code. Regards, PaulRyan. Quote Link to comment Share on other sites More sharing options...
etrader Posted August 28, 2011 Author Share Posted August 28, 2011 Thanks PaulRyan, I want to include everything that is really needed. If I include 10 files (instead of one), this is because of the fact that another page may onlye need file2 and file7 to be included. This is the reason that I asked this question. Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 29, 2011 Share Posted August 29, 2011 Opening 1 file vs opening 10 files... of course opening 10 files is going to be slower. However in most cases the difference in the amount of time taken is going to be so miniscule it is not worth consideration. Typically people are using multiple files for organizational purposes or the application of DRY. In other words, there is a good reason for keeping things in multiple files rather than sticking them in one big file. PHP also will not load an include file if the include is not reached at run time of the script, so if you have conditional includes, there is no concern in terms of performance. Finally, most people use an opcode cache like APC in production, which is going to cache scripts in shared memory. Quote Link to comment Share on other sites More sharing options...
Doug G Posted August 30, 2011 Share Posted August 30, 2011 Another reason to use specific include files rather than one big file is the way interpreted code works on the web server. When a php file is first loaded by the server, the entire script is "pre-processed" by the interpreter which builds a global list of functions, variables, etc so the code can execute properly. Only after this entire file scan completes does the code start executing. The time to load the file from the filesystem is much less than the time to do the initial file scan. As far as I know, anyway Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.