当前位置:网站首页>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自定义QTableView实例
- The solution that prompts "system group policy prohibits the installation of this device" under win10 system (home version has no group policy)
- 软件测试工程师的5年之痒,讲述两年突破瓶颈经验
- QT: QSS custom qsplitter instance
- 使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
- Basic usage of sqlmap
- 15 software testing Trends Worthy of attention
- Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
- 公司测试部门来了个00后卷王之王,老油条感叹真干不过,但是...
- Snownlp emotion analysis
猜你喜欢

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

11. Provider service registration of Nacos service registration source code analysis

QT: QSS custom qtableview instance

游戏测试相关 测试一个英雄的技能(春招被问比较多的一道题)

snownlp情感分析

How to realize automatic testing in embedded software testing?

Some abilities can't be learned from work. Look at this article, more than 90% of peers
![[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials](/img/e0/c2b1fbe99939d44201401abf1b5a72.png)
[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials

Software testing redis database

T5 的尝试
随机推荐
Qt:qss custom qlineedit instance
正常一英寸25.4厘米,在影像领域是16厘米
What are the strengths of "testers"?
你真的需要自动化测试吗?
MySQL -- index principle + how to use
Comment réaliser des tests automatisés pour les tests logiciels embarqués?
独家分析 | 关于简历和面试的真 相
Qt:qss custom qstatusbar instance
带你走进云原生数据库界扛把子Amazon Aurora
ExecutorException: Statement returned more than one row, where no more than one was expected.
Redis notes 01: Introduction
《通信软件开发与应用》
What happened to those who focused on automated testing?
Do you really need automated testing?
8年测试总监的行业思考,看完后测试思维认知更深刻
QT:QSS自定义 QScrollBar实例
年中了,准备了少量的自动化面试题,欢迎来自测
QT: QSS custom qtoolbar and qtoolbox instances
QT: QSS custom qtoolbutton instance
可以写进简历的软件测试电商项目,不进来get一下?