src/Connection/PhpiredisSocketConnection.php
private function connectWithTimeout($socket, $address, ParametersInterface $parameters)
    {
        socket_set_nonblock($socket);

        if (@socket_connect($socket, $address, (int) $parameters->port) === false) {
            $error = socket_last_error();

            if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
                $this->emitSocketError();
            }
        }

        socket_set_block($socket);

        $null = null;
        $selectable = array($socket);

        $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
        $timeoutSecs = floor($timeout);
        $timeoutUSecs = ($timeout - $timeoutSecs) * 1000000;

        $selected = socket_select($selectable, $selectable, $null, $timeoutSecs, $timeoutUSecs);

        if ($selected === 2) {
            $this->onConnectionError('Connection refused.', SOCKET_ECONNREFUSED);
        }

        if ($selected === 0) {
            $this->onConnectionError('Connection timed out.', SOCKET_ETIMEDOUT);
        }

        if ($selected === false) {
            $this->emitSocketError();
        }
    }
private function connectWithTimeout($socket, $address, ParametersInterface $parameters)
    {
        socket_set_nonblock($socket);

        if (@socket_connect($socket, $address, (int) $parameters->port) === false) {
            $error = socket_last_error();

            if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
                $this->emitSocketError();
            }
        }

        socket_set_block($socket);

        $null = null;
        $selectable = array($socket);

        $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
        $timeoutSecs = floor($timeout);
        $timeoutUSecs = ($timeout - $timeoutSecs) * 1000000;

        $selected = socket_select($selectable, $selectable, $null, $timeoutSecs, $timeoutUSecs);

        if ($selected === 2) {
            $this->onConnectionError('Connection refused.', SOCKET_ECONNREFUSED);
        }

        if ($selected === 0) {
            $this->onConnectionError('Connection timed out.', SOCKET_ETIMEDOUT);
        }

        if ($selected === false) {
            $this->emitSocketError();
        }
    }
private function connectWithTimeout ( $ socket , $ address , ParametersInterface $ parameters ) { socket_set_nonblock ( $ socket ) ; if ( @ socket_connect ( $ socket , $ address , ( int ) $ parameters -> port ) === false ) { $ error = socket_last_error ( ) ; if ( $ error != SOCKET_EINPROGRESS && $ error != SOCKET_EALREADY ) { $ this -> emitSocketError ( ) ; } } socket_set_block ( $ socket ) ; $ null = null ; $ selectable = array ( $ socket ) ; $ timeout = ( isset ( $ parameters -> timeout ) ? ( float ) $ parameters -> timeout : 5.0 ) ; $ timeoutSecs = floor ( $ timeout ) ; $ timeoutUSecs = ( $ timeout - $ timeoutSecs ) * 1000000 ; $ selected = socket_select ( $ selectable , $ selectable , $ null , $ timeoutSecs , $ timeoutUSecs ) ; if ( $ selected === 2 ) { $ this -> onConnectionError ( 'Connection refused.' , SOCKET_ECONNREFUSED ) ; } if ( $ selected === 0 ) { $ this -> onConnectionError ( 'Connection timed out.' , SOCKET_ETIMEDOUT ) ; } if ( $ selected === false ) { $ this -> emitSocketError ( ) ; } }
Opens the actual connection to the server with a timeout.

@param resource            $socket     Socket resource.
@param string              $address    IP address (DNS-resolved from hostname)
@param ParametersInterface $parameters Parameters used to initialize the connection.

@return string
Opens the actual connection to the server with a timeout .