Will including unnecessary php files slow down website?

前端 未结 9 1831
醉话见心
醉话见心 2020-12-20 15:23

The question might prompt some people to say a definitive YES or NO almost immediately, but please read on...

I have a simple website where there are 30 php pages (e

相关标签:
9条回答
  • 2020-12-20 15:23

    I live by "include as little as possible, as much as necessary" so i usually just include my config and session handling for everything and then each page includes just what they need using an include path defined in the config include, so for path changes you still just need to change one file.

    If you include everything the slowdown won't be noticeable until you get a lot of page hits (several hits per second) so in your case just including everything might be ok.

    0 讨论(0)
  • 2020-12-20 15:27

    You can migitate some of the disadvantages of PHP code-compiling by using XCache. This PHP module will cache the PHP-opcode which reduces compile time and performance.

    0 讨论(0)
  • 2020-12-20 15:28

    You should benchmark. Time the execution of the same page with different includes. But I guess it won't make much difference with 30 files.

    But you can save yourself the time and just enable APC in the php.ini (it is a PECL extension, so you need to install it). It will cache the parsed content of your files, which will speed things up significantly.

    BTW: There is nothing wrong with laziness, it's even a virtue ;)

    0 讨论(0)
  • 2020-12-20 15:38

    it's not a bad practice if the files are small and contains just definition and settings. if they actually run code, or extremely large, it will cause a performance issue. now - if your site has 3 visitors an hour - who cares, if you have 30000... that's another issue, and you need to work harder to minimize that.

    0 讨论(0)
  • 2020-12-20 15:41

    If your site is object-oriented I'd recommend using auto-loading (http://php.net/manual/en/language.oop5.autoload.php).

    This uses a magic method (__autoload) to look for a class when needed (it's lazy, just like you!), so if a particular page doesn't need all the classes, it doesn't have to get them!

    Again, though, this depends on if it is object-oriented or not...

    0 讨论(0)
  • 2020-12-20 15:42

    It will indeed slow down your website. Most because of the relative slow loading and processing of PHP. The more code you'd like to include, the slower the application will get.

    0 讨论(0)
提交回复
热议问题