A solution for sharing sessions between multiple Web servers

Source: Internet
Author: User
Tags sessions
Many of the development involved in the user's session validation is very reserved questions, the problem is more interesting, summed up a number of programs, only for reference.
   [question raised]
In order to meet a large enough application to meet more customers, so we set up the N Web server (n>=2), in the case of multiple Web servers, we will involve a problem: After users log on a server, If you can continue to use the client's session while crossing to another server?
(the scenario described below is only for the development architecture of Linux/unix Apache Mysql PHP, but it can also be extended to other platforms.) )
   [Problem Solution]
Since our problem has been put in front of, then we must from the technical point of view to solve the problem, to our customers a better experience, summed up a few programs.
   1. How to write client cookies
When the user login successfully, the site domain name, username, password, token, session valid time all in the form of cookies written to the client's cookie, if the user from a Web server across to another server, Our program to detect the client's cookie information, to judge, and then provide the corresponding services, of course, if the cookie expired, or invalid, nature will not let users continue to serve. Of course, the drawbacks of this approach are self-evident, such as the client has disabled cookies or cookies stolen by hackers?
  2. How the session data is synchronized between servers
Assuming that Web server A is a server to which all users log in, then when the user verifies that the session data is written to a server, then they can write their own scripts or daemons to automatically sync the session data to other Web servers, then when the user jumps to another server, Then the session data is consistent, and nature will be able to directly carry out the service without landing again. The disadvantage is that it may be slow, unstable, if it is one-way synchronization, the landing server problems, then other servers can not service, of course, may also consider the issue of two-way synchronization.
   3. How to share session data with NFS
In fact, this scheme and the following MySQL scheme is similar, but the storage mode is not the same. Basically, there is a common Server for NFS (Network File Server) to do a shared server, all Web servers log the session data to the server, then all the session data is actually stored on this NFS server, Regardless of user access to the Web server, the server to get the session data, then the sharing session data can be implemented. The disadvantage is that the dependency is too strong, if the NFS server down, then everyone will not work, of course, you can consider the form of multiple NFS server synchronization.
(The classic Article on NFS: http://linux.vbird.org/linux_server/0330nfs.php)

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.