GatewayClient如何可以判断GatewayWorker是否启动

辣条

如果服务没有启动就直接报错程序无法执行了 stream_socket_client(): unable to connect to tcp://127.0.0.1:1239 (Connection refused), 怎么可以判断下如果没有启动, 我想执行下面的程序呢?

4174 2 0
2个回答

mdx2007

try catch 下?

  • 暂无评论
辣条
    // $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
    }
  • 暂无评论
年代过于久远,无法发表回答
🔝