Home >Backend Development >PHP Tutorial >Analysis of php+mysql large user login solution, mysql user login_PHP tutorial

Analysis of php+mysql large user login solution, mysql user login_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:10:33720browse

php+mysql large user login solution analysis, mysql user login

This article analyzes the php+mysql mass user login solution through examples. Share it with everyone for your reference. The specific analysis is as follows:

Big companies such as Baidu, QQ, 360, etc. all have hundreds of millions of users. Not only do all sub-websites log in through one account, but they also open user platforms for other websites to use. This level of data volume and visits , if optimization is not done, it will probably go down soon. These companies have a dedicated team to maintain a registration and login, and the detailed design is very excellent. Now let’s briefly talk about their design plans.

When it comes to big data, the pressure is not on PHP, but mainly on MySQL. PHP can do load balancing. If 10 machines cannot handle it, just use 20 or 100. This is not a bottleneck.

But MySQL is a single point. No matter how many slaves are made, the query is optimized. Updating the data cannot be solved simply by adding a machine. Moreover, the query can also reduce the pressure through Memcache caching, so there is no need to do many slaves. For libraries, usually 1 master and 4 slaves are enough.

The following mainly introduces the database solutions:

Assume that users can log in through "login name", "email" or "mobile phone number".

The table structure is as follows:

Login name and ID table, divided into 100 tables according to login_hash

Copy code The code is as follows:
CREATE TABLE user_login(
login_name VARCHAR() User login name, which can be "login name", "email" or "mobile phone number" login
login_hash BIGINT HASH code of user login name
user_id BIGINT user ID
);
CREATE TABLE user_login0 LIKE user_login;
CREATE TABLE user_login1 LIKE user_login;
… …
CREATE TABLE user_login100 LIKE user_login;
ID and user information table, divided into 100 tables according to user_id

CREATE TABLE user_info(
user_id BIGINT user ID
login_pwd CHAR() User login password
… …Other information, home address, mobile phone number, gender, etc.
);

CREATE TABLE user_info0 LIKE user_info;
CREATE TABLE user_info1 LIKE user_info;
… …
CREATE TABLE user_info2 LIKE user_info;


Business implementation logic:

Depend on the server: implement a self-increasing ID service (equivalent to Oracle's sequence), or you can implement it yourself (either using PHP+MySQL or C). The purpose is to get the ID from this service. The number of IDs taken each time is +1 based on the last time. It is very similar to MySQL's autoincrement, except that it cannot be incremented inside the table.

Registration process:

1) Verify user name, email, mobile phone number, password and other formats. Omit…

2) Get an ID from the service, assuming it is 115.

3) If the user's login type is email (eg: $loginName='songhuan@zixue.it'), add the prefix login name result before the login name (eg: $loginName='mail_songhuan@zixue.it' )

4) Find the HASH value of the login name: $loginHash=md5($loginName); For the hash of the md5 value, you can find the asc code, or use your own algorithm, and finally get $loginHash=16-bit or 32-bit integer

5) $tableName = 'user_login' . ($loginHash%100), if you get the user_login table name, if the result is user_login88.

$tableName = 'user_info' . (115%100), if you get the user_info table name.

6) Execute SQL:

Copy code The code is as follows:
INSERT INTO user_login88 (login_name, login_hash, user_id) VALUES ('songhuan@zixue.it', 183239324323, 1) ;
INSERT INTO user_info15 (user_id, login_pwd) VALUES (115, 'afieflefiefladifadfadfe');

Login process:

1) If the user's login type is email (eg: $loginName='songhuan@zixue.it'), add the prefix login name result before the login name (eg: $loginName='mail_songhuan@zixue.it' )

2)

Copy code The code is as follows:
$loginHash=ord(md5($loginName));

3)

Copy code The code is as follows:
$tableName = 'user_login' . ($loginHash%100);
If the result for user_login88

4) Execute SQL:

Copy code The code is as follows:
SELECT id FROM user_login88 WHERE login_hash = $loginHash;

If the data cannot be queried, the login name does not exist

5) If id=115 can be obtained, then

Copy the code The code is as follows:
$tableName = 'user_info'.(115 %100);

SELECT id, pwd … FROM user_info15 WHERE id = 115;

6) Match passwords, if the passwords are not equal, return false

7) If the passwords are equal, encrypt the user ID and put it in COOKIE, and store the user information in Memcache.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/934927.htmlTechArticleAnalysis of php+mysql mass user login solution, mysql user login This article provides an example analysis of php+mysql mass user login solution plan. Share it with everyone for your reference. The specific analysis is as follows:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn