Session processing in distributed systems
Server Independent Session
As shown below:
Server-independent Session requires that each user request must be operated on the same application server, which requires the load balancing server to send the user's request to the server with the same address every time.
Server No. 1 that the first user accesses for the first time must be directed by the load balancing server to Server No. 1 throughout the user's session. Other servers will not save the session information of user No. 1.
Nowadays load balancing servers generally have this function (nginx)
But if the following situation occurs
When server No. 1 is down at this time, the load balancing server will divert user No. 1 Go to server No. 2 or No. 3, but the user does not have a secure context on servers No. 2 and No. 3. The server will notify the user to log in again. This user experience will definitely be affected. And it is very likely to cause user data loss.
Each server retains all sessions
Each server retains all user sessions. This is related to the issue of session synchronization between application servers, and the real-time requirements are relatively high. This method can avoid the problems encountered by the independent session of the above server, as shown in the figure below:
Advantages
In this method, even if the first situation occurs, the number 1 will be saved on servers 2 and 3. Session information, when the load balancing server fails and diverts user 1 to servers 2 and 3, the server will also find that there is the security context of user 1 and can continue to access without the need to log in again.
Disadvantages
But this method also has disadvantages, that is, the real-time requirements for Session synchronization of the application server are relatively high, and it will bring additional cross-band overhead, and when the Session changes remotely, synchronization is required. If the amount of information in the Session is relatively large, it will consume considerable memory.
Server Shared Session
Server Shared Session Information:
Advantages
The Session information of each user will be stored in another server outside the application (maybe a database or a KV storage service) , so that the application server does not need to store the Session information of each user, saving a lot of memory overhead.
When different application servers need to use Session information, go to the shared Session server to obtain the information.
In this way, the load balancing server does not need to assign users to a fixed server, and there is no need to copy session information between servers. When the session information changes, the application server can go to the shared server to modify the information.
Disadvantages
Relying on shared servers. Once there is a problem with the shared server or shared server cluster, users will be greatly affected
Transmitting Session data in Cookies
Storing user information in Cookies can eliminate an instability factors, but Cookies still have hidden dangers in terms of security, and Cookies also have length restrictions.
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });The above introduces the processing of Session in distributed systems, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

The working principle of cookies involves the server sending cookies, the browser storing cookies, and the browser processing and storing cookies. Detailed introduction: 1. The server sends a cookie, and the server sends an HTTP response header containing the cookie to the browser. This cookie contains some information, such as the user's identity authentication, preferences, or shopping cart contents. After the browser receives this cookie, it will be stored on the user's computer; 2. The browser stores cookies, etc.

With the popularity of the Internet, we use browsers to surf the Internet have become a way of life. In the daily use of browsers, we often encounter situations where we need to enter account passwords, such as online shopping, social networking, emails, etc. This information needs to be recorded by the browser so that it does not need to be entered again the next time you visit. This is when cookies come in handy. What are cookies? Cookie refers to a small data file sent by the server to the user's browser and stored locally. It contains user behavior of some websites.

The effects of clearing cookies include resetting personalization settings and preferences, affecting ad experience, and destroying login status and password remembering functions. Detailed introduction: 1. Reset personalized settings and preferences. If cookies are cleared, the shopping cart will be reset to empty and products need to be re-added. Clearing cookies will also cause the login status on social media platforms to be lost, requiring re-adding. Enter your username and password; 2. It affects the advertising experience. If cookies are cleared, the website will not be able to understand our interests and preferences, and will display irrelevant ads, etc.
