We have compiled some basic information about PHP. Please feel free to take a look.
Name | Comments |
IP | Internet Protocol |
ICMP | Internet Control Message Protocol , mainly used for routing to send error reports |
HTTP
HTTP is the abbreviation of Hyper Text Transfer Protocol. Its development is the result of cooperation between the World Wide Web Consortium and the Internet Engineering Task Force (IETF), which eventually released a series of RFCs. RFC 1945 defines the HTTP/1.0 version. The most famous of these is RFC 2616. RFC 2616 defines a version commonly used today - HTTP 1.1.
HTTP protocol (HyperText Transfer Protocol, Hypertext Transfer Protocol) is a transfer protocol used to transfer hypertext from the WWW server to the local browser. It can make the browser more efficient and reduce network transmission. It not only ensures that the computer transmits hypertext documents correctly and quickly, but also determines which part of the document is transmitted and which part of the content is displayed first (such as text before graphics), etc.
HTTP is an application layer protocol, consisting of requests and responses, and is a standard client-server model. HTTP is a stateless protocol.
Position in the TCP/IP protocol stack
The HTTP protocol is usually carried on top of the TCP protocol, and sometimes on top of the TLS or SSL protocol layer. At this time, it becomes our Often referred to as HTTPS. As shown in the figure below
The default HTTP port number is 80 and the HTTPS port number is 443.
HTTP request response model
HTTP protocol always initiates a request from the client and the server sends back a response. See the picture below
This limits the use of the HTTP protocol and cannot allow the server to push messages to the client when the client does not initiate a request. .
HTTP protocol is a stateless protocol. There is no correspondence between this request and the last request of the same client.
HTTP Request
The request message sent by the client to the server includes the following format
Get request example
GET /562f25980001b1b106000338.jpg HTTP/1.1Host img.mukewang.comUser-Agent Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36Accept image/webp,image/*,*/*;q=0.8Referer http://www.imooc.com/Accept-Encoding gzip, deflate, sdchAccept-Language zh-CN,zh;q=0.8
POST request example
POST / HTTP1.1Host:www.wrox.comUser-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)Content-Type:application/x-www-form-urlencodedContent-Length:40Connection: Keep-Alivename=Professional%20Ajax&publisher=Wiley
Part 1: Request line, the first line shows the request type, and http1.1 version .
Part 2: Request header, line 2 to line 6.
The third part: blank line, the blank line of the seventh line.
Part 4: Request data, line 8.
HTTP Response
Under normal circumstances, the server will return an HTTP response message after receiving and processing the request sent by the client.
HTTP response also consists of four parts
HTTP/1.1 200 OKDate: Fri, 22 May 2009 06:07:21 GMTContent-Type: text/html; charset=UTF-8<!--body goes here-->
The first part of the status line: consists of three parts: HTTP protocol version number, status code, and status message.
The second part of the message header: used to describe some additional information to be used by the client
The third part of the blank line: the blank line after the message header is required
The fourth part of the response text: The server returns to Client text message.
HTTP status code
The status code consists of three digits. The first number defines the response category, which is divided into five categories
Status |
Comments |
##1xx | Indication information--Indicates that the request has been received and continues to be processed |
2xx | Success--Indicates that the request has been successfully received, understood, and accepted |
3xx | Redirect- - Further operations must be performed to complete the request |
4xx | Client error--The request has a syntax error or the request cannot be fulfilled |
5xx | Server-side error--The server failed to fulfill a legal request |
Processes and Threads
The concept of process is the basis of the structure of the operating system. The designers of Multics first used this technical term in the 1960s, and it is more general than homework. Regarding the definition of process, it is as follows
An executing program.
An instance of a program running on a computer.
An entity that can be assigned to and executed by a processor.
A unit of activity described by a single sequential thread of execution, a current state, and a set of related system resources.
Why is the process designed?
It is very difficult to design a system software that can coordinate various different activities.
There are many jobs running at any time, and each job includes many steps that require execution in sequence, so it is not possible to analyze the sequence combination of time. In the absence of a system-level method for coordinating and cooperating across all activities, programmers are left to adopt their own ad hoc methods based on their understanding of the environment controlled by the operating system. However, this method is very fragile, especially to small errors in programming, because these errors only appear when rare time series occurrences occur.
Diagnosis can be difficult because of the need to distinguish these errors from application software errors and hardware errors. Detecting errors in a timely manner is also difficult to determine the cause because it is difficult to identify the precise scenario in which the error occurred. Generally speaking, the 4 main reasons for this type of error are as follows:
A system is required to solve these problems Level methods monitor the execution of different programs in the processor. The concept of process provides the basis for this.
So the process can be seen as consisting of three parts
A program that can be executed
What the program needs Related data
Execution context of the program
Creation of the process
Traditionally, the way the operating system creates processes has a negative impact on the user and applications are transparent, which is also common in contemporary operating systems. But it would be useful to allow one process to trigger the creation of another process.
For example, a program process can spawn another process to accept data generated by the application and organize the data into a format suitable for later analysis. New processes run in parallel with the application and are activated when new data is available.
This scheme is very useful for structuring applications, for example, a server process (such as a print server, file server) can spawn a new process for each request it handles. When the operating system spawns a new process in response to an explicit request from another process, this action is called process forking.
When a process forks another process, the former one is called the parent process, and the spawned process is called the child process. In a typical situation, related processes require communication and cooperation between agents. For programmers, collaboration is a very difficult task.
What is a thread
A thread is an execution stream of a process. A thread cannot allocate system resources. It is a part of the process and is a smaller independent running unit than the process
The relationship between processes and threads
A process is like a landlord, with land (system resources), and a thread is like a tenant (thread, executing the farming process). Each landlord (process) only needs one working tenant (thread).
Process - the smallest unit of resource allocation, relatively robust, crashes generally do not affect other processes, but switching processes consumes resources and is less efficient.
Thread - the smallest unit of program execution. There is no independent address space. If one thread dies, the entire process may die, but it saves resources and has high switching efficiency.
Common processes and threads in PHP
In web applications, every time we access php, we create a PHP process, and of course we will also create at least one PHP thread
PHP uses pcntl for multi-process programming
PHP uses pthreads for multi-thread programming
nginx has only one thread per process, and each thread can handle access from multiple clients
php-fpm uses a multi-process model, and each process has only one thread. Threads can only handle one client access
Apache may use a multi-process model or a multi-thread model, depending on which SAPI is used
Related recommendations:
Five ways to communicate between AS3 and PHP (based on HTTP protocol)_PHP tutorial
Communication between PHP and Linux processes
##Http protocol post request parameters in PHP, php protocol post request_PHP tutorial
The above is the detailed content of Basic explanation of communication protocols and processes and threads in PHP. For more information, please follow other related articles on the PHP Chinese website!