src/GcpExtensionChannel.php
public function getConnectivityState($try_to_connect = false)
    {
        // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel
        // object is closed, we only mark this Object to be invalid. Thus, we need a global variable
        // to mark whether this GCPExtensionChannel is close or not.
        if ($this->is_closed) {
            throw new \RuntimeException("Channel has already been closed");
        }
        $ready = 0;
        $idle = 0;
        $connecting = 0;
        $transient_failure = 0;
        $shutdown = 0;
        foreach ($this->channel_refs as $channel_ref) {
            $state = $channel_ref->getRealChannel($this->credentials)->getConnectivityState($try_to_connect);
            switch ($state) {
                case \Grpc\CHANNEL_READY:
                    $ready += 1;
                    break 2;
                case \Grpc\CHANNEL_FATAL_FAILURE:
                    $shutdown += 1;
                    break;
                case \Grpc\CHANNEL_CONNECTING:
                    $connecting += 1;
                    break;
                case \Grpc\CHANNEL_TRANSIENT_FAILURE:
                    $transient_failure += 1;
                    break;
                case \Grpc\CHANNEL_IDLE:
                    $idle += 1;
                    break;
            }
        }
        if ($ready > 0) {
            return \Grpc\CHANNEL_READY;
        } elseif ($idle > 0) {
            return \Grpc\CHANNEL_IDLE;
        } elseif ($connecting > 0) {
            return \Grpc\CHANNEL_CONNECTING;
        } elseif ($transient_failure > 0) {
            return \Grpc\CHANNEL_TRANSIENT_FAILURE;
        } elseif ($shutdown > 0) {
            return \Grpc\CHANNEL_SHUTDOWN;
        }
    }
public function getConnectivityState($try_to_connect = false)
    {
        // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel
        // object is closed, we only mark this Object to be invalid. Thus, we need a global variable
        // to mark whether this GCPExtensionChannel is close or not.
        if ($this->is_closed) {
            throw new \RuntimeException("Channel has already been closed");
        }
        $ready = 0;
        $idle = 0;
        $connecting = 0;
        $transient_failure = 0;
        $shutdown = 0;
        foreach ($this->channel_refs as $channel_ref) {
            $state = $channel_ref->getRealChannel($this->credentials)->getConnectivityState($try_to_connect);
            switch ($state) {
                case \Grpc\CHANNEL_READY:
                    $ready += 1;
                    break 2;
                case \Grpc\CHANNEL_FATAL_FAILURE:
                    $shutdown += 1;
                    break;
                case \Grpc\CHANNEL_CONNECTING:
                    $connecting += 1;
                    break;
                case \Grpc\CHANNEL_TRANSIENT_FAILURE:
                    $transient_failure += 1;
                    break;
                case \Grpc\CHANNEL_IDLE:
                    $idle += 1;
                    break;
            }
        }
        if ($ready > 0) {
            return \Grpc\CHANNEL_READY;
        } elseif ($idle > 0) {
            return \Grpc\CHANNEL_IDLE;
        } elseif ($connecting > 0) {
            return \Grpc\CHANNEL_CONNECTING;
        } elseif ($transient_failure > 0) {
            return \Grpc\CHANNEL_TRANSIENT_FAILURE;
        } elseif ($shutdown > 0) {
            return \Grpc\CHANNEL_SHUTDOWN;
        }
    }
public function getConnectivityState ( $ try_to_connect = false ) { // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel // object is closed, we only mark this Object to be invalid. Thus, we need a global variable // to mark whether this GCPExtensionChannel is close or not. if ( $ this -> is_closed ) { throw new \ RuntimeException ( "Channel has already been closed" ) ; } $ ready = 0 ; $ idle = 0 ; $ connecting = 0 ; $ transient_failure = 0 ; $ shutdown = 0 ; foreach ( $ this -> channel_refs as $ channel_ref ) { $ state = $ channel_ref -> getRealChannel ( $ this -> credentials ) -> getConnectivityState ( $ try_to_connect ) ; switch ( $ state ) { case \ Grpc \ CHANNEL_READY : $ ready += 1 ; break 2 ; case \ Grpc \ CHANNEL_FATAL_FAILURE : $ shutdown += 1 ; break ; case \ Grpc \ CHANNEL_CONNECTING : $ connecting += 1 ; break ; case \ Grpc \ CHANNEL_TRANSIENT_FAILURE : $ transient_failure += 1 ; break ; case \ Grpc \ CHANNEL_IDLE : $ idle += 1 ; break ; } } if ( $ ready > 0 ) { return \ Grpc \ CHANNEL_READY ; } elseif ( $ idle > 0 ) { return \ Grpc \ CHANNEL_IDLE ; } elseif ( $ connecting > 0 ) { return \ Grpc \ CHANNEL_CONNECTING ; } elseif ( $ transient_failure > 0 ) { return \ Grpc \ CHANNEL_TRANSIENT_FAILURE ; } elseif ( $ shutdown > 0 ) { return \ Grpc \ CHANNEL_SHUTDOWN ; } }
Get the connectivity state of the channel

@param bool $try_to_connect try to connect on the channel

@return int The grpc connectivity state
@throws \InvalidArgumentException
Get the connectivity state of the channel