How to prevent multiple requests from being submitted to the same address at the same time in php?-php Tutorial

Source: Internet
Author: User
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 ..

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.