Will including unnecessary php files slow down website?

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

    Considering the size of your website; if you haven't noticed a slowdown, why try to fix it?

    When it comes to larger sites, the first thing you should do is install APC. Even though your current method of including files might not benefit as much from APC as it could, APC will still do an amazing job speeding stuff up.

    If response-speed is still problematic, you should consider including all your files. APC will keep a cached version of your sourcefiles in memory, but can only do this well if there are no conditional includes.

    Only when your PHP application is at a size where memory exhaustion is a big risk (note that for most large-scale websites Memory is not the bottleneck) you might want to conditionally include parts of your application.

    Rasmus Lerdorf (the man behind PHP) agrees: http://pooteeweet.org/blog/538

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

    It will slow down your site, though probably not by a noticable amount. It doesn't seem like a healthy way to organize your application, though; I'd rethink it. Try to separate the application logic (eg. most of the server-side code) from the presentation layer (eg. the HTML/CSS).

    0 讨论(0)
  • 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.

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