如果服務(wù)沒有啟動就直接報錯程序無法執(zhí)行了 stream_socket_client(): unable to connect to tcp://127.0.0.1:1239 (Connection refused), 怎么可以判斷下如果沒有啟動, 我想執(zhí)行下面的程序呢?
// $this->ws 127.0.0.1:1239
public function isWsStart()
{
try {
$client = stream_socket_client('tcp://' . $this->ws, $errno, $errmsg, 3);
} catch (\Exception $e) {
return false;
}
return true;
}
public function isOnline($uid)
{
Gateway::$registerAddress = $this->ws;
return Gateway::isUidOnline($uid); //在線返回1 不在線返回0
}