php – Is multiple includes bad for performance?


If I use too many includes on my page will it slow it down or something?


The include doesn't slow down the page, but the content of the file that will be included.

The performance depends on the content of your file that will be included, for example, too many FOR cycles make the script slower, a database connection with a poorly built query , etc…

The best thing would be to look for how to improve your php script performance, development best practices, etc…

Only the include function will not affect performance. Now if you compare a require() with an include() yes, require is slower compared to include .

Use absolute paths when calling files, so php won't need to parse the include_path .

Here are some examples of good practices for you who are just starting out:

  1. The php manual will be your best friend and will answer (almost) all your questions.
  2. Look for DRY(Don't Repeat Yourself) and KISS(Keep It Simple Stupid) practices , in other words, don't repeat code and keep everything stupidly simple.
  3. Beauty is not essential, but a well-organized code makes the system much easier to maintain.
  4. Use comments, but remove them in the production used version, comments are welcome but make the arches heavier (next item completes this)
  5. Minifying files can be a good solution, as spaces and comments will be removed and some variables modified to improve performance and decrease file weight (in the case of javascript , less traffic).
Scroll to Top