Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of oversold goods inventory with High concurrency of PHP

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "PHP high concurrency how to solve the problem of oversold commodity inventory". In daily operation, I believe that many people have doubts about how to solve the problem of oversold commodity inventory with high concurrency of PHP. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to solve the problem of oversold commodity inventory with PHP high concurrency". Next, please follow the editor to study!

The pressure of high concurrency on database

For the first problem, use caching to deal with it, avoiding direct manipulation of the database, such as using Redis.

How to solve the problem of oversold goods in inventory under competitive conditions

For the second question, it needs to be emphasized.

Conventional writing: query the inventory of the corresponding goods, determine whether the inventory quantity is greater than 0, and then perform operations such as generating orders, but in judging whether the inventory is greater than 0, there will be problems if there is a high concurrency, resulting in negative inventory.

Test table sql

Import the data like the following table into the database

/ * Navicat MySQL Data TransferSource Server: 01 Local localhostSource Server Version: 50553Source Host: localhost:3306Source Database: testTarget Server Type: MYSQLTarget Server Version: 50553File Encoding: 65001Date: 2020-11-06 14:31:35*/SET FOREIGN_KEY_CHECKS=0 -Table structure for products---DROP TABLE IF EXISTS `products` CREATE TABLE `products` (`id`int (10) NOT NULL AUTO_INCREMENT COMMENT 'ID', `title` varchar (50) DEFAULT NULL COMMENT' item name', `store`int (11) DEFAULT'0' COMMENT', PRIMARY KEY (`id`) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COMMENT=' item list' -Records of products-- INSERT INTO `products` VALUES ('1cm,' Daohuaxiang Rice', '20') -Table structure for order_log---DROP TABLE IF EXISTS `order_ log` CREATE TABLE `log log` (`id` int (10) unsigned NOT NULL AUTO_INCREMENT, `content` varchar (255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT 'log content', `c _ time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'creation time', PRIMARY KEY (`id`) ENGINE=MyISAM DEFAULT CHARSET=latin1 -Table structure for order---DROP TABLE IF EXISTS `order` CREATE TABLE `order` (`oid` bigint (20) unsigned NOT NULL DEFAULT'0' COMMENT 'order number', `product_ id` int (11) DEFAULT'0' COMMENT 'merchandise ID', `number`int (11) DEFAULT' 0' COMMENT 'purchase quantity', `ctime`timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'creation time', PRIMARY KEY (`oid`) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT=' order table'; order processing code issued

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report