每次重啟的時(shí)候(無論是restart獲取reload)都會(huì)導(dǎo)致出現(xiàn) unable to connect to tcp://127.0.0.1:2306 (Connection refused) ,我大概知道是什么原因引起的,但是不知道怎么解決
比如說我在close調(diào)用getClientIdByUid ,每當(dāng)我重啟的時(shí)候,就會(huì)導(dǎo)致getClientIdByUid 調(diào)用報(bào)錯(cuò),不知道該如何處理,跪求大家?guī)蛶兔?,重啟的時(shí)候不僅僅onClose會(huì)報(bào)錯(cuò),也會(huì)有onMessage里面調(diào)用Gateway::getUidByClientId的報(bào)錯(cuò)
public static function onClose($client_id)
{
$user_id = $_SESSION['user_id'] ?? 0;
$exist = Gateway::getClientIdByUid($user_id);
if (empty($exist)) {
Db::name('user')->where('id', $user_id)->update(['is_online' => 0, 'offline_time' => datetime()]);
}
}
2023-05-15 22:03:12 pid:10107 ErrorException: stream_socket_client(): unable to connect to tcp://127.0.0.1:2306 (Connection refused) in /data/www/comechat_wss/vendor/workerman/gateway-worker/src/Lib/Gateway.php:761
重啟過程中有些進(jìn)程會(huì)退出,這時(shí)候有業(yè)務(wù)處理需要進(jìn)程通訊就會(huì)報(bào)錯(cuò),這個(gè)報(bào)錯(cuò)是正常的。
如果你是更新數(shù)據(jù)庫在線狀態(tài),按照你現(xiàn)在的方法,重啟時(shí)需要考慮將數(shù)據(jù)庫在線狀態(tài)全部歸零,否則會(huì)有數(shù)據(jù)不準(zhǔn)確。
推薦用一個(gè)定時(shí)器定時(shí)執(zhí)行Gateway::getAllUidList(),得到的結(jié)果去更新數(shù)據(jù)庫,這樣性能更好,結(jié)果準(zhǔn)確。