Php+mysql large number of user login solution analysis, MySQL user login
This paper analyzes the Php+mysql large number of user login solutions. Share to everyone for your reference. The specific analysis is as follows:
Baidu, QQ, 360 and other large companies have hundreds of millions of users, not only all subsites through an account login, but also open the user platform, provided to other sites to use, this level of data volume and access, if not optimized, estimates will soon go down, these companies are a dedicated team, Maintain a registered login, detailed design is very good, and now roughly talk about their design plans.
Big data time, the pressure is not PHP, mainly in mysql,php can do load balance, 10 machines cannot resist 20 or 100 units, this is not a bottleneck.
But MySQL is a single point, no matter how much from the library, is to optimize the query, update data can not just simple by adding the machine to solve, and the query is also able to reduce the pressure through the memcache cache, so do not have to do much from the library, the general 1 Master 4 from on it.
The following is the main introduction of the following database solutions:
Assume that a user can sign in by login name, mailbox, or phone number.
The table structure is as follows:
Login name and ID table, according to Login_hash 100 sheets
Copy the Code code as follows: CREATE TABLE User_login (
Login_name VARCHAR () User login name, can be login, mailbox, or phone number
Login_hash BIGINT User Login name hash code
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, according to USER_ID 100 sheets
CREATE TABLE User_info (
USER_ID BIGINT User ID
Login_pwd CHAR () User login password
... ... Other information, home address, cell 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:
Dependent server: A service that implements a self-increment ID (equivalent to Oracle's sequence), or it can be implemented on its own (either with Php+mysql or with C). The goal is to be able to take the ID from this service, each time the number of IDs is +1 on the previous basis, and the MySQL autoincrement very much like, but can not be self-increment inside the table.
Registration process:
1) Verify the format of user name, mailbox, phone number, password, etc. Omitted...
2) take an ID from the service, assuming it is 115.
3) If the user's logon type is a mailbox (for example: $loginName = ' songhuan@zixue.it '), prefix the login result with the login name (e.g. $loginName = ' mail_songhuan@zixue.it ')
4) hash value of the login name: $loginHash =md5 ($loginName); For MD5 value hash, you can find the ASC code, or use your own algorithm, the final $loginhash=16 bit or 32-bit integer
5) $tableName = ' User_login '. ($loginHash%100), if the User_login table name is obtained, if the result is user_login88.
$tableName = ' User_info '. (115%100), if you get the User_info table name.
6) Execute SQL:
Copy the Code code 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 (+, ' afieflefiefladifadfadfe ');
Login process:
1) If the user's logon type is a mailbox (for example: $loginName = ' songhuan@zixue.it '), prefix the login result with the login name (e.g. $loginName = ' mail_songhuan@zixue.it ')
2) Copy code code as follows: $loginHash =ord (MD5 ($loginName));
3) Copy the Code as follows: $tableName = ' user_login '. ($loginHash%100); If the result is user_login88
4) Execute SQL: copy code code as follows: SELECT ID from user_login88 WHERE login_hash = $loginHash;
If the query does not have data, the login name does not exist
5) If you can get to id=115, copy the Code code as follows: $tableName = ' user_info '. (115%100);
SELECT ID, pwd ... From user_info15 WHERE id = 115;
6) Match password, if password is not equal, return false
7) If the password is equal, the user ID is encrypted into a cookie, and the user information is deposited into memcache.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/934927.html www.bkjia.com true http://www.bkjia.com/PHPjc/934927.html techarticle Php+mysql A large number of user login solution analysis, MySQL user login This article analyzes the Php+mysql a large number of user login solutions. Share to everyone for your reference. The specific analysis is as follows: ...