Having a single entry point to a website. Bad? Good? Non-issue?

前端 未结 9 1203
你的背包
你的背包 2020-12-15 05:16

This question stems from watching Rasmus Lerdorf\'s talk from Drupalcon. This question and his talk have nothing specifically to do with Drupal, by the way... it was just gi

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

    Like anything in software development, it depends. Rasmus's objection to the front-controller style frameworks is the performance hit you take from having to load so much code up-front on each request. This is 100% true. Even if you're using a smart-resource loading module/object/etc of some kind, using a framework is a performance trade-off. You take the performance hit, but in return you get back

    1. Encouraged seperation of "business logic" (whatever that is) and Template/Layout Logic

    2. Instant and (more importantly) unified access to the objects you'll use for database queries, service called, your data model, etc.

    To a guy like Rasmus, this isn't worth the performance hit. He's a C/C++ programmer. For him, if you want to separate out business logic in a highly performant way, you write a C/C++ Extension to PHP.

    So if you have an environment and team where you can easily write C/C++ extensions to PHP and your time-to-market vs. performance ratio is acceptable, then yes, throw away your front-controller framework.

    If that's not your environment, consider the productivity increases a front-controller framework can bring to your (likely) simple CRUD Application.

    0 讨论(0)
  • 2020-12-15 05:23

    This is what I thought at first, but it doesn't seem to be an impact. After all, your entry point is (usually) only doing a couple of things: setting some environment constants, including the bootstrap loader, optionally catching any exceptions thrown and dispatching the front controller. I think the reason that this is not inefficient is because this file does not change depending on the controller, action or even user.

    I do feel this is odd however. I'm building a small MVC framework myself at the moment but it's slightly reverse to most frameworks I've used. I put controller logic in the accessed file. For example, index.php would contain the IndexController and it's actions. This approach is working well for me at least.

    0 讨论(0)
  • There are definitely disadvantages to using a front-controller file architecture. As Saem explains, accessing the same file is generally advantageous to performance, but as Alan Storm and Rasmus Lerdorf explain, trying to make code handle numerous situations (such as a front-controller tries to handle the request to every "page" on the site) leads to a bloated and complicated collection of code. Using a bloated and complicated collection of code for every page load can be considered bad practice.

    Saem is arguing that a front-controller can save you from having to edit code in multiple locations, but I think that in some cases, that is better solved by separating out redundancies.

    Having a directory structure that is actually used by the web server can make things simpler for the web server and more obvious for the developers. It is simpler for a web server to serve files by translating the url into the location as they would traditionally represent than to rewrite them into a new URL. A non-front-controller file architecture can be more obvious to the developer because instead of starting with a controller that is bloated to handle everything, they start with a file/controller that is more specific to what they need to develop.

    0 讨论(0)
  • 2020-12-15 05:30

    I think one of the biggest advantages you have over having only a single point of entry is security. All of the input going in is less likely to corrupt the system if it is checked and validated in a single place.

    0 讨论(0)
  • 2020-12-15 05:34

    Just to add, the thing people usually think is that, since there is one php page, it is a single page serving all requests. Sort of like queuing.

    The important thing to note is that, each request creates an instance of the script and thus, the load is the same as if two different pages were being accessed at the same time. So, still the same load. Virtually.

    However, some frameworks might have a hell whole lot of stuff you don't need going on in the entry script. Sort of like a catchall to satisfy all possible scenarios, and that might cause load.

    Personally, I prefer multi pages, the same way I mix oop and procedural. I like php the old school way.

    0 讨论(0)
  • 2020-12-15 05:36

    The important thing is that you use a web framework that supports scalability through methods like load-balancing and declarative code.

    No, a single-entry point does not in itself make a bottleneck. The front page of Google gets a lot of hits, but they have lots of servers.

    So the answer is: It doesn't matter.

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