DoraRPC\Client::getClientObj PHP Метод

getClientObj() приватный Метод

get current client
private getClientObj ( )
    private function getClientObj()
    {
        //config obj key
        $key = "";
        //if not spc will random
        switch ($this->connectMode) {
            case 1:
                $key = $this->getConfigObjKey();
                $clientKey = $this->serverConfig[$this->connectGroup][$key]["ip"] . "_" . $this->serverConfig[$this->connectGroup][$key]["port"];
                //set the current client key
                $this->currentClientKey = $clientKey;
                $connectHost = $this->serverConfig[$this->connectGroup][$key]["ip"];
                $connectPort = $this->serverConfig[$this->connectGroup][$key]["port"];
                break;
            case 2:
                //using spec
                $clientKey = trim($this->connectIp) . "_" . trim($this->connectPort);
                //set the current client key
                $this->currentClientKey = $clientKey;
                $connectHost = $this->connectIp;
                $connectPort = $this->connectPort;
                break;
            default:
                throw new \Exception("current connect mode is unknow", -1);
                break;
        }
        if (!isset(self::$client[$clientKey])) {
            $client = new \swoole_client(SWOOLE_SOCK_TCP | SWOOLE_KEEP);
            $client->set(array('open_length_check' => 1, 'package_length_type' => 'N', 'package_length_offset' => 0, 'package_body_offset' => 4, 'package_max_length' => 1024 * 1024 * 2, 'open_tcp_nodelay' => 1));
            if (!$client->connect($connectHost, $connectPort, DoraConst::SW_RECIVE_TIMEOUT)) {
                //connect fail
                $errorCode = $client->errCode;
                if ($errorCode == 0) {
                    $msg = "connect fail.check host dns.";
                    $errorCode = -1;
                } else {
                    $msg = \socket_strerror($errorCode);
                }
                if ($key !== "") {
                    //put the fail connect config to block list
                    $this->serverConfigBlock[$this->connectGroup][$key] = 1;
                }
                throw new \Exception($msg . " " . $clientKey, $errorCode);
            }
            self::$client[$clientKey] = $client;
        }
        //success
        return self::$client[$clientKey];
    }