How to Prevent Repeated Writing of Data under php High Concurrency

  ios, question

The front-end interface requesting php to write data is too frequent, resulting in a large amount of duplicate data in mysql. How to deal with it

This question answers back and forth from three aspects:

Front end

The front-end should limit the request by disabled the submit button or setting a timer to prevent users from submitting multiple requests.


Interface must do a good job of limit, but this is not the key to solve this problem, because you can’t set a limit to1 time per min. Why pay attention to this point is because sometimes the user is not a person, may be a malicious program.

Back-end services

Personally, I think this is the key point. It includes PHP and Mysql. I don’t know what your data is. I give an example of Sina Weibo. If a user writes a microblog and clicks on it twice, you will see What? Two identical microblogs? No way, you can come to me when there is one. The simplest way is to cache the last data and then check if it was submitted repeatedly. Mysql structure should be designed well. If your data is unique, then your fields and primary keys should be designed to ensure uniqueness.

There are so many codes first, there are many solutions, you can search for them.