Web software architecture principles

Source: Internet
Author: User
Tags php switch

I. The directory structure is clear and should not be too deep or complicated. It is best to use relative addresses for paths
Ii. Proper naming
3. Change the content and interface to make the template better.
Iv. centralized storage of common public information
5. The include file cannot be embedded more often.
6. Too many content files cannot be stored in the directory
7. Data structure should be reasonably designed
8. data verification should be performed on the server side
9. Connect to the database nearly late and disconnect the database nearly early
10. Use session and cookie as few as possible

Detailed description:

(1) the directory structure is clear and should not be too deep or complicated. It is best to use a relative address for the path.
A) What kind of directory and what kind of content can be easily managed, so that the directory structure of the web program can be clearly understood and the functional modules and content stored in a folder can be seen at a glance. If you store them as needed, you will not know what a directory is for a long time. For example, the commonly used executable files must be stored in the (Project root directory) root directory, so that you can easily understand their functions and enter less address characters in the program. The images used by the program are stored in the images directory under the root directory. If the project is large and many branches exist, you can create directory names related to the branches in the directory, store related image content. The configuration file and common function class inventory of the program are placed in the include directory. The extension of the function class library file stored in this directory must be named :. PHP switch is not named. inc. files with extensions such as ini are mainly used to prevent users from downloading these files or accessing their source code, so that they can be easily called. The template file should be stored in the templatesdirectory under the root directory, and the extension name is .html. If the project is large and there are many categories, the template files can be classified and stored in the bottom directory. Temporary files are stored in the tmp directory of the root directory, which is usually set to readable and writable by anyone. The relative address is used to facilitate program transplantation.

(2) Proper naming
A) it is best to name the program. If a word is to be described, it is named in lower case. If it is to be described by multiple words, it is also connected by an underscore between lower case words. Note that the name cannot be too long, which makes it inconvenient. Although the expression can be clearer, it is difficult to type. The function names in the program can also be the same. Well, there are also some, that is, every name takes time to think about a more appropriate name, it is not easy for us who have poor English comments. (Miserable, haha !)

(3) change the content and interface frequently to make the template better.
A) It is better to change the content and interface to Use templates. This is because when I feel that a non-page is not fashionable one day, I want to replace a newer and better interface, and I can use it now. If the HTML page content is put in a program to process input according to the traditional production, it is difficult to change the program, which may cause great inconvenience in case of a change error, this is not very good. (The program has not been maintained for a long period of time and suddenly needs to be changed. It is inevitable that no correction or error will occur for a while ). If a template is used, you don't need to change the program. You just need to change the template file. Well, the benefits of my template seem to be no good for the traditional method. It seems that the product is not worth the money. No, the template also has its own disadvantages, now I also want to talk about how it is bad. The traditional method is to embed HTML code into a web program. The advantage of this method is that the execution speed is faster than that of the template, because it can be directly output without any processing, templates are different. The template must first open and read the template file to a string variable that can be an array of string variables. Is this time required? It takes time to replace the template variables with string operation functions after reading them? After the replacement is completed, you can enter the output. Which of the following do you think is better for traditional practices and template-based practices? (I personally think that if you are developing a website with a large access volume, it is a good choice to choose the traditional method. What I am talking about is relatively not absolute, if the traffic volume is large, it cannot be written in the script language, and it should be CGI + socket + demon. Don't talk about it. Let's talk about it. Haha)

(4) Unified Storage of common public information
A) Unified Storage of common public information, mainly to facilitate the most common functions that can be called during team development, every developer does not need to copy one copy or write one copy of the file stored in the program. This wastes space and results in poor efficiency.

(5) include files cannot be embedded more often.
A) The include file cannot be embedded much. This is because each time the program includes a file, it is necessary to open and read the file. This is time-consuming, in other words, you may encounter bugs that are difficult to find during path processing.

(6) Too many content files cannot be stored in the directory.
A) Too many content files cannot be stored in the directory. Have you found out? It takes longer to open the System32 folder on Windows than to open other folders? This is mainly because there are many files in the System32 folder. When you open the system, you have to spend time searching for the files and display them? If a large number of files are large, it is best to split the Directory into drive letters for processing. If your machine is good enough and strong enough, if I haven't said it, I have to talk about it separately.

(7) data structure should be reasonably designed
A) The data structure should be properly designed. If the data structure design is unreasonable, no matter how detailed your program is written, it is easy to write, and it is not impossible to play its biggest role and value. This is equivalent to a woman's biggest and most plump chest, but the person is not tall enough, and black, poor health, frame and disability, will you say she is beautiful and perfect? The same is true for programs, where some code crashes and does not work, so it is useless to exist. The data structure should be simplified and clear.

(8) data verification should be performed on the server side

A) data verification should be performed on the server. This is because, even if someone else does not input data from our page, he or she makes a get URL) or you have made a form to transmit data in post mode, and our program will also go to check. If it is placed on the client, others will be able to escape the review using the above method. However, when the data volume is large, the server loads and runs, and the audit of data integrity can overhead time and system resources. The client does not occupy too many resources on the server, because it occupies user resources.

(9) connecting to the database is nearly late and disconnecting is nearly early
A) the connection to the database is nearly late, And the disconnection is nearly early. This is mainly because it takes time to connect to the data, right? If the connection is not instantly used, will it also occupy system resources? Is there a limit on the number of database connections? Therefore, you have to connect as late as possible and disconnect the connection as soon as possible. This operation can minimize the amount of system resources used and provide conditions for the next connection.

(10) Use as few sessions and cookies as possible
A) Try to use fewer sessions and cookies, because the use of sessions takes up system resources. sessions are stored on the server end, and each time you read the data in the session, it is quite open. Although cookies do not occupy server resources, they are not secure.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.