Home >Backend Development >PHP Tutorial >Detailed explanation of how web programs work, detailed explanation of how web works_PHP tutorial
1. Working principle of Web program
(1) The meaning of the word Web
Network: [Computer] Computer network, network
Web: [Computer] World Wide Web, Internet
Web programs, as the name suggests, are programs that work on the Web.
(2) Working principle of stand-alone program
A stand-alone computer, that is, a computer that is not connected to other computers and is not in a network. For example: There are two single machines A and B. Program X is only installed on A. If you want to get the running results of X on B, you must install X on B and then run it. If there are many computers in Class B, you need to install and run them one by one. They cannot communicate and collaborate directly with each other. As shown in Figure 1.
(3) Working principle of client/server program
Connect stand-alone computers into a network, such as connecting A and B into a network, so that services can be provided between them, such as A providing services to B. Common services are file sharing, FTP file downloading, etc. We call the computer that provides (responds to) services a server (Server), and the computer that accepts (requests) services is called a client (Client), also called workstations (Workstations). The working principle of the client/server program is shown in Figure 2.
The roles of server and client can be switched. A computer can provide services to itself. At this time, it is both a server and a client. For example, if computer A shares its own folder a, and then finds A on the network, it can download a, which means that it has provided services to itself and requested and responded to the services.
This client/server collaboration method between computers is called the C/S method, or C/S architecture.
The C/S program is divided into two parts: server side and client side, which are called server-side program (or service program) and client program (or client program) respectively. For client programs, each client must be installed separately. This is the same as the distribution of stand-alone programs, and it is also very troublesome. However, after the client program is installed, you can interact with the server through the communication line, or communicate with other clients through the server. A typical example is the commonly used chat program QQ, as shown in Figure 3.
(4) Working principle of browser/server program
If you send a request to the server through the browser in the client and receive the response result, then, at this time, we call this collaboration method the B/S method, or B/S architecture. The working principle is shown in Figure 4:
At this time, the client program is the browser, and the installation of the browser is completed with the installation of the operating system, and does not require additional installation by the user. For them, when using B/S programs (such as reading news online, sending and receiving emails), they do not need to install special client programs and can operate directly in the browser. This makes the maintenance of the B/S program very convenient, because you don't need to worry about the client program, you only need to maintain the server program.
(5)Composition of C/S and B/S servers
A server is a machine responsible for service tasks. These service tasks are generally completed by specialized software. Generally speaking, server software with certain service functions and the machine on which it is located are collectively called XX servers (XX represents a specific service). These software can be concentrated in one machine (Figure 5), such a machine can be called a centralized server; or they can exist alone in a certain machine (Figure 6), such a machine can be called a stand-alone server. Multiple stand-alone servers can form a server farm or matrix.
According to service tasks, several common server software are shown in Table 1.
Server-side script: A program written in a server-side programming language.
Server-side programming language: a programming language that only runs on the server side and is interpreted and executed by the server, such as PHP language.
(6)The specific process of B/S program work (as shown in Figure 7)
(7) The specific process of PHP program work
The specific process is a collaboration process between Apache, PHP, and browsers:
The user requests a PHP file from the server through the browser (for example, enter: http://localhost/index.php) in the address bar. Apache searches for the PHP file requested by the browser in the user document release directory on the server. If found If not, an error message will be returned to the browser; otherwise, it will be submitted to the PHP interpreter for interpretation and execution. The PHP interpreter will perform syntax analysis on the PHP file. If a syntax error is found, an error message will be returned via Apache (based on the browser's capabilities). Represented by recognized code) to the browser, otherwise the PHP program (which may include operations on the database MySQL) is executed, and the PHP program execution result (expressed by code recognized by the browser) is returned to the browser via Apache, and the browser returns The results are interpreted and executed, and the execution results are displayed in the browser window.
If the file requested by the browser is not a PHP file, but an HTML file or JavaScript file. The process will be simplified: Apache looks for the HTML file or JavaScript file requested by the browser in the user document release directory on the server. If it cannot find it, it returns an error message to the browser. Otherwise, it returns it to the browser. The browser The returned results are interpreted and executed, and the execution results are displayed in the browser window.
2. Browser working process
(1) Web client working process
Any application system must have an interface that provides user operations, that is, the user interface. The work of the browser, from the perspective of the entire B/S program, is an interface (interface) for users to interact with the B/S program. Its mission is:
A. Collect user input data
B. Send user data to server
C. Receive the response returned by the server
D.Explain and execute these codes
It can be seen that the browser plays the role of an agent for the server to the user. This agent has the role of collecting messages, requesting responses, and interpreting instructions sent back by the server.
(2)Web client code
Whether it is organizing the interface used to collect user data, or interpreting instructions from the server to form the resulting interface, they are all implemented in web client code. Commonly used web client codes include HTML language, JavaScript language, CSS, XML and other languages.
3.How HTML works
(1) Introduction to HTML
HTML: HyperTextMarkupLanguage, hypertext markup language.
In the late 1980s, Tim Berners-Lee (the father of WWW), who worked at the European Laboratory for Particle Physics (CERN: the European Laboratory for Particle Physics), discovered through research that people’s visual processing is page-based. So he came to a conclusion: electronic data should be presented in pages. With this as a starting point, he used hypertext-centric management methods to organize information on the Internet, and proposed methods for accessing and browsing web pages: he established a hypertext markup language; he designed the Hypertext Transfer Protocol (HTTP: Hypertext Transport Protocol). ), used to obtain hyperlink files; use Uniform Resource Locator (URL: UniformResourceLocator) to locate network files, sites or servers.
(2) How HTML works
HTML is not essentially a programming language, but a markup language. The so-called mark is also called a label in some books. From an object-oriented perspective, it means the identification of browser objects. It is used to control the performance of browser sub-objects such as text and images in the browser, as well as how to establish tags for links between files. These tags are placed in text format files. The biggest difference between programs is that they can be used to control the operating system or application program to execute and complete a certain job. Hypertext Markup Language documents should be as formal as possible to have the same effect whether opened in any browser on any operating system.
(3) Basic structure of HTML
A. Version statement, Prologue
B. Head
C.Body