当前位置:网站首页>php如何解决高并发问题
php如何解决高并发问题
2022-07-03 09:45:00 【dj1540225203】
- 悲观锁,将库存字段number字段设为unsigned,当库存为0时,因为字段不能为负数,将会返回false,当高并发来时,可能会导致连接数用完,系统数据库奔溃
- 使用for update ,锁定操作的行
- FIFO,使用Redis先进先出,但是这有点又变成单线程的影子,如果内存不够还是会异常
- 文件锁,当关键方法中使用文件锁,这样操作完才释放锁。
- 乐观锁,增加一个version字段判断是否被更新过,但如果使用主从有延迟应该强制读主库。
- 使用redis的watch
<?php
$redis = new redis();
$result = $redis->connect('127.0.0.1', 6379);
echo $mywatchkey = $redis->get("mywatchkey");
echo "抢购成功!<br/>";
echo "剩余数量:".($rob_total-$mywatchkey-1)."<br/>";
echo "用户列表:<pre>";
var_dump($mywatchlist);
}else{
$redis->hSet("watchkeylist","user_".mt_rand(1, 9999),'meiqiangdao');
echo "手气不好,再抢购!";exit;
}
}
?>边栏推荐
- Software testing (test case) writing: vulgar, native and skillful
- QT:QSS自定义QTableView实例
- 8年测试工程师总结出来的《测试核心价值》与《0基础转行软件测试超全学习指南》
- MySQL -- index principle + how to use
- Basic theoretical knowledge of software testing -- app testing
- 有些能力,是工作中学不来的,看看这篇超过90%同行
- How does MySQL find the latest data row that meets the conditions?
- Small file special
- 软件测试工程师的5年之痒,讲述两年突破瓶颈经验
- 15 software testing Trends Worthy of attention
猜你喜欢

I, a tester from a large factory, went to a state-owned enterprise with a 50% pay cut. I regret it

ByteDance layoffs, test engineers were almost destroyed: how terrible is the routine behind the recruitment of large factories?

QT:QSS自定义 QTreeView实例

做软件测试三年,薪资不到20K,今天,我提出了辞职…

QT: QSS custom qtabwidget and qtabbar instances

那些一門心思研究自動化測試的人,後來怎樣了?

我,大厂测试员,降薪50%去国企,后悔了...

.Net Core-做一个微信公众号的排队系统

Multiple IO transfer - preamble

QT: QSS custom qtableview instance
随机推荐
How to make a blood bar in the game
11. Provider service registration of Nacos service registration source code analysis
软件测试工程师的5年之痒,讲述两年突破瓶颈经验
QT: QSS custom qtabwidget and qtabbar instances
glassfish org. h2.server. Shutdownhandler classnotfoundexception exception exception handling
2022 pinduogai 100000 sales tutorial
Cause: org. apache. ibatis. builder. Builderexception: error parsing SQL mapper configuration problem analysis
Communication software development and Application
Bid -- service commitment -- self summary
The testing department of the company came to the king of the Post-00 roll, and the veteran exclaimed that it was really dry, but
. Net core - a queuing system for wechat official account
Word line and bit line
T5 attempt
QT:QSS自定义 QRadioButton实例
Qt:qss custom qspinbox instance
The solution that prompts "system group policy prohibits the installation of this device" under win10 system (home version has no group policy)
Redis notes 01: Introduction
软件测试必学基本理论知识——APP测试
C language project: student achievement system
QT:QSS自定义 QSlider实例