Php+mysql How to prevent the situation of inventory being oversold due to concurrency
Source: Internet
Author: User
Php+mysql how to prevent concurrency causing inventory to be oversold.
Site encounters such as group purchase, second kill, special events such as the time, but inventory is limited, the current situation is, if a commodity has only one inventory, at this time there are two users at the same time, the inventory will become 1, also shows that two users have bought, but I have only one inventory, how to solve this problem?
------to solve the idea----------------------
Database lock, select for update:
Control inventory with cache. Every time decrement ... After the order is not paid back again set back
------to solve the idea----------------------
1. Handling of Things
In general, transaction processing can be resolved, I use this side is basically this
2. Each reduction of inventory corresponding to an order serial number (this order serial number in the generation of reduced inventory this user action will be generated), the order serial number is the table of self-increment ID, and then statistics this water, it is good to solve it!
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.