0

Possible Duplicate:
Why is require_once so bad to use?

I'm trying to speed up a site (cms) I am developing, and it's a lot of code. I have a lot of class files (about 10) and a few function files, all of which are in the config.php file. On every single page I use require_once("config.php"); which then includes all my class files.

Here's my question: Most of my class files are made for individual pages (such as viewArticle.class.php is only used on the page to display the article), does it slow down my script to still have these files included in the config.php if they are not being used?

I just wanted to see if anyone knew the exact answer or had any experience before I spend all my time coming up with a solution so only the files that need to be used are ran.

Basically, does it slow down my script to include class files if they are not going to be used?

Thanks

Community
  • 1
  • 1
Dan
  • 41
  • 3
  • @Henrik P. Hessel I think the question is more about including non-used files than `require_once`. – jeroen May 18 '11 at 22:55

2 Answers2

1

require_once() will only parse the file once, and won't incur any significant performance hit for subsequent calls. However, if you require() a file that never gets used, then you are gaining unnecessary overhead for the parser to load and parse the code.

On a small site with relatively low traffic, it should not have a terrible impact on your server resources, however as the traffic scales up, all the unnecessary includes may start to affect performance.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • The site gets about 12 Million + pageviews a month, so I assume something this small could have an effect. Thanks for your help. – Dan May 18 '11 at 23:27
0

If you are just talking about classes and class files, you might want to look into __autoload. That will only load files and classes as they are requested / used.

jeroen
  • 91,079
  • 21
  • 114
  • 132
  • spl_autoload_register (http://www.php.net/spl_autoload_register) is better in my opinion since it makes multiple loaders possible. – runfalk May 18 '11 at 23:25