Is PHP Single Entry Required

  ios, question

For some projects done before, this is how they usually come when they organize their structures:

/application
____/pc
________/controllers
________/views
____/mobile
________/controllers
________/views
/system
____/library
____/models
____/services
____system.php
/public
____/pc
________/assets
________index.php
____/mobile
________/assets
________index.php
/upload
/data

(Sorry, the UL/OL of this God Editor is really useless)

Application: application directory, system: system directory, public: website entry, upload: upload directory, data: cache session, etc.

Domain name is bound to /public/pc, and moves Addon domain to /public/mobile. Each index.php defines its own application path to indicate the corresponding /Controllers and /views to the route. In addition, it require the system portal /system/system.php to implement constant definition, initialization and application startup.

Because it is a database, so /models are put into /system for public use. model is only a simple table mapping and set/get/cure method. in order to maximize reuse (e.g. pc station and mobile station both need the publishing function of a module), business operations are directly moved into /services. action only performs the simplest parameter filtering, calls service to execute business and redirect.

Here comes the question:

Recently, I plan to build a travel website. To be sure, there are only pc and mobile terminals. APP application is not considered for the time being. Originally, I was thinking of using the single portal above. However, the function of the website is really limited. Several portals are fully qualified. Moreover, multi-portal saves routing operations. Direct access to business logic can squeeze some performance. Although the parameters of single portal can be changed with htaccess, it is definitely not as simple and clear as multi-portal. The core system.php of the require system in each header of multiple entries can also implement some functions such as system initialization, parameter filtering, and loading of library functions.

Since the website is completely done by itself, team cooperation does not exist at all. So, is it possible to reuse pc stations and mobile stations with multi-portal plus system portal including plus services plus DAO (it feels that according to the top form, do you have to write Controllers twice …), and most importantly, does single portal affect the implementation of load balancing including master-slave database (because there has never been such a scenario)?

In fact, my main entanglements are two points: 1. Reuse (it is of course more efficient to mix all the way to Hard coding, but it is a bit silly for the mobile terminal to rewrite it again); 2. Performance, performance, and possible future compressive strength.

First answer your title question

Is PHP Single Entry Required

The answer is definitelyno. The reason why there are more single entrances is that most popular frameworks are single entrance models. As for the advantages and disadvantages, you have carefully considered them, and the advantages and disadvantages are also the wise see wisdom, so you will not do it.

1, reuse (direct Hard coding mixed write all the way to the end, of course, the efficiency is higher, but the mobile side to write again is really a bit silly);

You also said that program execution efficiency-programmer maintenance efficiency, this is an irreconcilable contradiction, under this contradiction must be

  • High execution efficiency and low maintenance efficiency
  • (All kinds of compromises)
  • Low execution efficiency and high maintenance efficiency

No matter what kind of language or design decision, it is actually looking for a compromise point. You have to determine where your compromise point is, sometimes sacrificing some performance, but bringing about improvement in maintenance efficiency, then it is not unacceptable.

Take your multi-portal as an example, it is nothing more than include the same logic in the same portal of your multiple businesses (in extreme cases, the same logic is changed into one and then it is your previous mode). You can abstract the single-portal “request” and design it as a “business request”, and fine-tune your logic in this direction. This is your multi-portal mode.

2. Performance, performance, and possible future compressive strength.

The performance problem of 80% is not the php program itself, but the resources (such as mysql and file storage) that php and php are connected to. Instead of considering php, it is better to think about how to optimize php’s access efficiency to resources. If you optimize php’s access efficiency to resources to the fullest extent, perhaps you will adopt phalcon or directly replace php with another Compiled language.