How to prevent multiple requests from being submitted simultaneously to the same address at the same time in PHP

Source: Internet
Author: User
How to prevent multiple requests from being submitted simultaneously to the same address at the same time in PHP
Title, for example, there is a method in which the logic is probably as follows:


function Test () {
$a = $db->query (' ... ');//returns 1 or 0
if ($a = = 1) {
$db->set (0);//The next execution of this method after the update is no longer 1.
Here is the other logic, the problem is that if many requests call this method at the same time, and the set procedure in this method is a little longer, then the logic here will be executed multiple times, which is inconsistent with the expected execution only once.
}
}


How do you generally deal with this situation? This is a lot of the case with high security requirements such as voting or prizes.
If the request may come from a different IP, if you use a cache such as memcached to save the state, there is also a network delay, SHMOP.

------Solution--------------------
End!
You're a god-thinking man! People like us can't guess what you're asking for, and when you're done with your masterpiece, be sure to give us these ordinary people.
  • 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.