Will require_once affect the performance?

I am building a website and I chunked the html codes (for display) like this: head <head>, header <body>, main display <body> and footer <body>.

It is something like this:

<!doctype html>
   //some php stuff here
   require_once 'head.php';
   require_once 'header.php';
   //some php stuff here
   require_once 'display.php';
   require_once 'footer.php';

Will this affect the performance of the website?

Have you run any tests to see the time difference?

In localhost? Not yet. But from what I know the test will be different in Development and Production site? Am I right?

The difference in rendering the web-page is negligible.

Usually the server handles the required scripts, PHP is then processed and the HTML script is sent to the browser to render.

The bottleneck is usually the time it takes to send the HTML script over the internet.

1 Like

every instruction will affect the performance.

1 Like

I don’t think you need be concerned about time. The things to think about are whether to use include or require and whether or not to use once

The way I look at it is

  • include - when I want something but it isn’t a critical FAIL if it doesn’t get included
  • require - when it is absolutely necessary and a FAIL would result in major breakage
  • once - if there is a chance there might be “can’t redefine” errors. I find this is generally a safe default except when I intentionally want to get something more than once
1 Like

So I will be okay I continue this kind of coding? No slowness on performance?

I will use require_once.

1 Like

I find this a very good technique because it is very easy to change a required filename, make changes and when satisfied keep the changes.

With lengthy scripts it is difficult not to create problems when making changes and drastically simplifies debugging.

There will be an extremely slight difference in loading time usually about a couple of milliseconds. Compared to debugging time I would not be concerned over the additional time taken to load the required script.

1 Like

As chorn stated, every bit of code will take up some time. But as long as it’s like .00056 ms. Does it make much difference?

The thing you will need to be careful about using require_once is getting the path and file name right. One wrong or misspelled name, typo or case mismatch, and the script will die right there.


Thank you!

Thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.