当前位置:网站首页>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;
}
}
?>
边栏推荐
- glassfish org. h2.server. Shutdownhandler classnotfoundexception exception exception handling
- Communication software development and Application
- QT:QSS自定义 QSplitter实例
- Qt:qss custom QSlider instance
- Nuget add reference error while installing packages
- 17K薪资要什么水平?来看看95后测试工程师的面试全过程…
- Software testing redis database
- Strategic management of project organization
- Qt:qss custom qradiobutton instance
- MySQL checks for automatic updates at 0:00 every day
猜你喜欢
QT:QSS自定义 QScrollBar实例
The normal one inch is 25.4 cm, and the image field is 16 cm
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
Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
QT:QSS自定义QTableView实例
Game test related tests a hero's skills (spring moves are asked more questions)
Use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
帶你走進雲原生數據庫界扛把子Amazon Aurora
Qt:qss custom qpprogressbar instance
17K薪资要什么水平?来看看95后测试工程师的面试全过程…
随机推荐
Imread change image display size
QT:QSS自定义 QTreeView实例
The solution that prompts "system group policy prohibits the installation of this device" under win10 system (home version has no group policy)
Wechat applet training 2
QT: QSS custom qtreeview instance
My understanding of testing (summarized by senior testers)
Comment réaliser des tests automatisés pour les tests logiciels embarqués?
snownlp情感分析
Wechat applet training notes 1
独家分析 | 关于简历和面试的真 相
Use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
In the middle of the year, I have prepared a small number of automated interview questions. Welcome to the self-test
Some abilities can't be learned from work. Look at this article, more than 90% of peers
《通信软件开发与应用》
What are the strengths of "testers"?
软件测试(测试用例)编写之俗手、本手、妙手
ConstraintLayout跟RelativeLayout嵌套出现的莫名奇妙的问题
QT:QSS自定义QListView实例
10. Nacos source code construction
Flink -- built in function (all)