Generally, multiple users can log on at the same time, but sometimes the customer needs to log on with only one account at the same time. let's take a look at the solution to this problem. I have considered this problem before. Today, it is very fast, from research to development... generally, multiple users can log on at the same time, but sometimes the customer needs to log on with only one account at the same time. let's take a look at the solution to this problem.
I have considered this problem before. today I have implemented it. it's very fast. I 've been researching and developing for almost four hours. it's a bit like QQ and logging on to two computers, one will squeeze the other and prompt the login information from other locations.
I. implementation principle
1. the user logs on to computer A, the session information is stored in redis, and the session_id is saved to the mysql database.
2. log on to the same user on Computer B. After verifying the user name and password, read the user information from the database and obtain the session_id of the user on computer, then, verify that the session has expired in redis.
3. if it expires, do not use the openfire push prompt. If the message does not expire, after php pushes messages using openfire, it deletes the session that the user logged on to in computer A in redis. after deletion, put the user's personal information logged on to computer B in the session, and update the session_id logged on to computer B to the database. in this case, you must first send the push and then clear the session, otherwise, the user cannot receive messages sent from xmpp on computer.
Note:Openfire is a type of java cms with its own database. the root user table of the user table you create must be in a certain relationship (such as mobile phone number and email address ), facilitate information push.
The same session_id must be logged on to the same media. in this case, you do not need to update the database or push messages.
The following describes the installation process and precautions.
2. install the tools used
# Yum install php-fpm nginx mysql-server redis php-devel php-pdo php-mysql
Modify the session storage mode:
# Vim/etc/php-fpm.d/www. conf; php_value [session. save_handler] = files // comment out the old one; php_value [session. save_path] =/var/lib/php/session php_value [session. save_handler] = redis // add the following php_value [session. save_path] = "tcp: // fig: 6379"
After the service is started, if the following content indicates that the session is successfully stored in redis.
Redis telnet View session
Redis telnet View session
Openfire: http://www.igniterealtime.org/downloads/
# Rpm-ivh./*. rpm // download the rpm installation package
After openfire is started, access http: // ip: 9090, which is configured step by step. one thing to note is the database encoding.