Web Services in layman's

Source: Internet
Author: User
Tags session id

For those who have not done web development, web development involves a lot of nouns, apache,nginx,cgi,php,http,cookie,session. What is this big piece of stuff, and here we go from the network level to figure out these things.

1. What is HTTP

For the web is always the thing is HTTP, then what is HTTP? The official statement is Hyper Text Transfer Protocol, from which it is also judged that HTTP is a protocol and is an application-layer protocol that corresponds to the transport-layer protocol TCP. So ultimately, HTTP is an application-layer protocol based on TCP.

For the server, is a passive connection process, so it is generally initiated by the client TCP connection request, and send data, because the TCP stream has no boundary characteristics, must agree to a protocol to determine the end of the data, HTTP protocol format as follows:

Therefore, for an HTTP server, only need to follow the above message format to receive the packet unpacking is possible.

2. What is Cookie/session

First, the cookie, which is managed by the browser, so it can be modified by JS. It is generally stored in client memory, so the cookie disappears automatically when the browser is closed during the lifetime of the browser session. Of course, if the cookie is set to expire, it will also be synced to the disk by the browser. During each HTTP request, the browser selects a portion of the cookie in the background and sends it to the Web server in the HTTP header. So the direct result of a cookie being too long is that the HTTP packet is too large, so the HTTP protocol has a limit on the length of the cookie.

The session can be seen as a server-side hash table, the default is stored as a file, key is the session Id,session ID will be stored in the cookie, so each time the server untied HTTP packets, according to the session in the cookie The ID can be in the hash table data. So the problem is, if the user in the browser to ban the cookie, can not find the session? Of course not, there are many other ways to disable cookies, which can be put back in the HTTP package, can be placed in other fields of the Baotou, such as Get parameters, can also be placed in the package body, such as post parameters, this kind of thing cannot be stumped programmer's

3. What is Apache and Nginx

If they are an HTTP server (and of course, other feature), it is simple to understand that they are an implementation of the HTTP protocol, namely, filter-----------filter------the package------is a brief of nginx.

4. What is the general Web architecture?

is a common web schema, consisting of a reverse proxy server, HTTP server, the HTTP server is divided into Nginx process and PHP process, any link problem can cause the browser error page.

First, exposed to the user is a reverse proxy server , the existence of reverse proxy has several functions, one is load balancing, the reverse proxy server receives the packet will follow a certain load balancing algorithm forwarded to the real Business Server, another role is to prevent attacks, It will filter out a lot of illegal requests according to certain rules, thus reduce the load of the business machine, because it simply forwards, there is no real business logic, so even if the hacker attack to this layer is not much harm. At the same time, the reverse proxy server can also cache some static resources, further reduce the load of the business machine.

Nginx, as an HTTP server, is primarily responsible for the hold connection throughout the architecture, not the actual processing of requests, which is drawn as a block in, but itself a multi-process structure.

Joined to the same machine configured with 8 Nginx workers, each worker configured the number of connections is 1024, then the ability of the machine hold the connection is 8*1024.

Nginx worker and PHP-FPM communication mode is through the socket to communicate, so nginx and PHP-FPM can be deployed on the same machine can also be deployed on different machines. Now the data is forwarded to the PHP-FPM, and its structure is basically similar to Nginx. PHP-FPM is a plug-in for PHP that is now integrated into PHP's core code and is an implementation of fast-cgi. FASTCGI rules each time a request comes in, pick a process from the process pool to load and execute a PHP script that will return the city to the process pool after the script is finished. So PHP-FPM is ultimately a process manager, as its name implies (FastCGI process manager). We can see in fastcgi mode, a process is corresponding to a request, if said on a machine we configured 300 fastcgi process, then it can handle the maximum number of requests is 300, is far less than the access capability of Nginx. If PHP has some blocking calls, the current process cannot process the other requests asynchronously, so PHP-FPM is a bottleneck in this architecture.

Web Services in layman

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.