In php, how does one prevent multiple requests from being submitted simultaneously to the same address at the same time, for example, there is a method in which the logic is roughly as follows: functiontest () {& nbsp; $ a $ db-& gt; query (...); returns 1 or 0 & nbsp; if ($ a1) {& nbsp; $ db-& gt; set (0); this method is executed next time after the update $ a is no longer 1. how to prevent multiple requests from being submitted to the same address at the same time in php?
For example, there is a method. The logic is roughly as follows:
Function test (){
$ A = $ db-> query ('...'); // return 1 or 0
If ($ a = 1 ){
$ Db-> set (0); // This method will be executed next time after the update $ a will no longer be 1.
// Here is other logic. The problem is that if many requests call this method at the same time and the set process in this method is a little longer, the logic here will be executed multiple times, it is not consistent with the expected execution only once.
}
}
How do you deal with this situation? This is often the case when high security requirements such as voting or prize-winning are required.
If session is used, the request may come from different ip addresses. if memcached is used for cache and storage, there is also a network delay? High opinion.
------ Solution --------------------
End!
You are a God-class thinker! People like us cannot guess what you want. when you finish your masterpiece, you must show it to those of us ..