当前位置:网站首页>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;
}
}
?>边栏推荐
- 年中了,准备了少量的自动化面试题,欢迎来自测
- Qt:qss custom qgroupbox instance
- QT:QSS自定义QListView实例
- QT: QSS custom qtoolbar and qtoolbox instances
- 软件测试——Redis数据库
- I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
- snownlp情感分析
- STM32F1与STM32CubeIDE编程实例-TM1637驱动4位7段数码管
- sqlmap基本使用方法
- 硬 货 | 一改测试步骤代码就全写?为什么不试试用 Yaml实现数据驱动?
猜你喜欢

QT:QSS自定义 QProgressBar实例

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

12. Nacos server service registration of source code analysis of Nacos service registration

UI interface design related knowledge (I)

STM32F1与STM32CubeIDE编程实例-TM1637驱动4位7段数码管

在职美团测试工程师的这八年,我是如何成长的,愿技术人看完都有收获

T5 的尝试

带你走进云原生数据库界扛把子Amazon Aurora

T5 attempt

What kind of living condition is a tester with a monthly salary of more than 10000?
随机推荐
8年测试工程师总结出来的《测试核心价值》与《0基础转行软件测试超全学习指南》
What is the salary level of 17k? Let's take a look at the whole interview process of post-95 Test Engineers
QT:QSS自定义QToolBar和QToolBox实例
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
Differences among norm, normalize and normalized in eigen
Clion debug
QT:QSS自定义 QTreeView实例
C language project: student achievement system
值得关注的15种软件测试趋势
T5 的尝试
Comment réaliser des tests automatisés pour les tests logiciels embarqués?
Error installing the specified version of pilot
glassfish org. h2.server. Shutdownhandler classnotfoundexception exception exception handling
软件测试工程师的5年之痒,讲述两年突破瓶颈经验
QT: QSS custom qtreeview instance
The highest monthly salary of 18K has a good "mentality and choice", and success is poor "seriousness and persistence"~
Wechat applet training notes 1
软件测试——Redis数据库
15 software testing Trends Worthy of attention
Software testing redis database