Jump to content

Does "include" take time?


etrader

Recommended Posts

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)?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.