I have encountered a few minor questions during the php interview today. please help me check it out.

Source: Internet
Author: User
Tags website server
I have encountered a few questions during the php interview today. could you please help me? 1. the website server wants to determine the behavior record of a user on the Internet and the next time the user logs on again, it can determine that the user was logged on last time. This is determined by cookie, or use session? Why? There is another question: how does the server determine whether A behavior is A user's or B's behavior. (I don't have a few questions about cookie and sessio's interview with php today. please help me check it out.
1. the website server wants to determine the behavior record of a user on the Internet and the next time the user logs on again, it can determine that the user was logged on last time. This is determined by cookie, or use session? Why? There is another question: how does the server determine whether A behavior is A user's or B's behavior. (Although there are many explanations for cookies and sessions on the Internet, I have never understood this question by 100%. it is estimated that this problem will happen in the next interview. how should I understand it ?)

2. how can I prevent this account from logging on again in other places after an account is logged on? for example, if an account of QQ is logged on, I want to use this account to log on elsewhere, how does php determine and block it?

3. there was very little data in a table at first, but because of the business relationship, the data volume soared (tens of millions or more). how should we design this table and optimize it?



------ Solution --------------------
1. good cookie. The Session is used to connect to the server to match the data. Queries the database.
2. You can set the is_login field in the database to log in and judge it as 1. if it is not logged in, it is 0. if it is already set as 1, it is determined that it has logged in again.
3. Just think of indexes. This is required

New comments. Do not spray
------ Solution --------------------
There is no unified answer to the question of the landlord.
1. Large websites use cookies and use sessions for security. Although session can also be set up with a validity period, cookies are generally preferred for the validity period.
How does the server determine whether A behavior belongs to user A or user B? This is identity recognition. It can be obtained from a cookie or session, or a user object is generated.

2. this cannot be solved. Only the Database ID can be set. Is_login is regarded as 1. But the problem is when to clear this identifier. --- Expert answers.

3. when indexing is simple, but indexing is inefficient. It can be divided into tables and partitions. It is only available after testing based on your query requirements.




------ Solution --------------------
1. the best way to use cookies is to use cookies + Sessions. you have to take a closer look at some tutorials, and many of them will not be pasted here.

2. use memchace + mysql to solve the problem, easy...

3. it is very general... this has happened in many cases, so I think it should be handled according to the actual situation.

For example, we can observe the mysql-slow.log first...

When the data volume is large, the first consideration may be table sharding...

------ Solution --------------------
Interview... answer:

Tens of millions. I didn't take the case for hundreds of millions of users in my previous company ......
------ Solution --------------------
Discussion

Interview... answer:

Tens of millions. I didn't take the case for hundreds of millions of users in my previous company ......

------ Solution --------------------
Discussion

1. the best way to use cookies is to use cookies + Sessions. you have to take a closer look at some tutorials, and many of them will not be pasted here.

2. use memchace + mysql to solve the problem, easy...

3. it is very general... this has happened in many cases, so I think it should be handled according to the actual situation.

For example, we can observe the mysql-slow.log first...

When there is a large amount of data, the first consideration may be ......

------ Solution --------------------
It should be the memcache expiration time setting to clear the is_login information in mysql, and then through some assistance such as onbeforeunload.
------ Solution --------------------
Discussion

It should be the memcache expiration time setting to clear the is_login information in mysql, and then through some assistance such as onbeforeunload.

------ Solution --------------------
[3. there was very little data in a table at first, but because of the business relationship, the data volume soared (tens of millions or more). how should we design this table and optimize it ?]

So what's the relationship? a table with csdn 6 million records is in the same table and exported.
------ Solution --------------------
I also want to know the answer to the second question, because when a non-human click exits (such as closing the browser or shutting down abnormally) occurs, if is_login is used to determine the answer, it will become invalid. If it is cleared regularly, there will also be a problem, that is, the login fails due to the failure to process is_login in time when an abnormal exit occurs.
------ Solution --------------------
The second problem is the same as counting the number of online users.


------ Solution --------------------
The second problem may be the use of socket. io.
It may be better to make judgments in a timely manner.
Because php cannot accurately determine whether it is online.

Another solution is the php solution.
Set the number of minutes that the online user did not perform any operations, so I decided that the user had exited. (each click event is an update online_time)
In addition, if there is a later login, you do not stop it, but ask him to log on, and then prompt the previously logged-on account to log on to your account elsewhere.

The first question: I suggest you prefer session security.

The third problem is: re-design the table if promised... maybe this is a better way.
If not, it is best to look at the specific situation... but you should consider optimization and table sharding.


------ Solution --------------------
Can the second question be considered as single-point logon?
------ Solution --------------------
Discussion

The second problem may be the use of socket. io.
It may be better to make judgments in a timely manner.
Because php cannot accurately determine whether it is online.

Another solution is the php solution.
Set the number of minutes that the online user did not perform any operations, so I decided that the user had exited. (each click event is an update online_time)
In addition, if there is a later login, you do not stop it, but ask him to log on, and then prompt the previously logged-on account to log on to your account elsewhere.

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.