Will including unnecessary php files slow down website?

前端 未结 9 1875
醉话见心
醉话见心 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:48

    As others have said, it shouldn't slow things down much, but it's not 'ideal'.

    If the main issue is that you're too lazy to go changing the paths for all the included files (if the path ever needs to be updated in the future). Then you can use a constant to define the path in your main file, and use the constant any time you need to include/require a file.

    define('PATH_TO_FILES', '/var/www/html/mysite/includes/go/in/here/');
    
    require_once PATH_TO_FILES.'database.php';
    require_once PATH_TO_FILES.'sessions.php';
    require_once PATH_TO_FILES.'otherstuff.php';
    

    That way if the path changes, you only need to modify one line of code.

提交回复
热议问题