as无效 mysql_mysql 排它锁无效
閑來無事,用slim做一個(gè)小東西(每次訪問會(huì)向數(shù)據(jù)庫插入一條記錄),然后用ab測(cè)試,壓力測(cè)試100次,但是查看數(shù)據(jù)庫只有88條記錄(應(yīng)該是100條啊);
ab -n 100 -c 100 "http://192.168.100.162/url?url=http://www.baidu.com"
上代碼
public function encode(string $url): string
{
$this->db->pdo->beginTransaction();
$nextId = $this->getNextId();// 從數(shù)據(jù)庫獲取最大ID
$shortUrl = $this->from10_to62($nextId);
$result = $this->saveRecord($nextId, $url, $shortUrl);
if (empty($result)) {
$this->db->pdo->rollBack();
return false;
}
file_put_contents('/var/tmp/log.txt', $nextId . PHP_EOL, FILE_APPEND);
$this->db->pdo->commit();
return true;
}
// 獲取最大值,加了悲觀鎖
private function getLastId():int
{
$result = $this->db->query('select max(id) as last_id from record for update')->fetchAll();
return !empty($result) ? (int)$result[0]['last_id'] : 1;
}
看日志
但是還是沒有100條記錄,
各路神仙,我這是哪里出了問題啊?
總結(jié)
以上是生活随笔為你收集整理的as无效 mysql_mysql 排它锁无效的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: #模拟触手机屏幕_从操作系统的改变谈手机
- 下一篇: mysql中以下正确的sql是_总结My