我是在webman用使用GatewayWorker,之后做一些數(shù)據(jù)庫的查詢新增操作
// 啟動(dòng)事務(wù)
Db::startTrans();
try {
$Hardwaredata = json_decode(trim($param), true);
if ($Hardwaredata === null || !array_key_exists("xwst", $Hardwaredata)) {
$this->StatusReturn(0, $client_id);
return;
}
if($Hardwaredata['xwst']==1){
if($boxinfo){
//執(zhí)行一些數(shù)據(jù)庫查詢和插入的操作
Gateway::sendToClient($client, $send_datas);
return;
}else{
Gateway::sendToClient($client, $send_datas);
return;
}
}
DB::commit();//提交至數(shù)據(jù)庫
} catch (\Throwable $e) {
DB::rollback();//數(shù)據(jù)庫回滾
}
我在使用事務(wù)的時(shí)候,我在Gateway::sendToClient 給用戶發(fā)送消息 我就想不執(zhí)行下面代碼了 我就return了,但是貌似這個(gè)會(huì)變成數(shù)據(jù)庫的數(shù)據(jù)沒有提交,這樣數(shù)據(jù)沒有插入成功。這種情況怎么辦呀
人才 你終于出現(xiàn)了 事務(wù) 必須提交 然后 最好是使用try catch 防止 出現(xiàn)大量事務(wù)不提交 導(dǎo)致死鎖 問題