Q: Connect application to Gsuite using PHP and IMAP using fsockopen function My application uses PHP (Codeigniter) and IMAP library.
I've a specific application requirement where by earlier the web-mail server was getting connected / accessed using fsockopen by passing host, port and login credentials and retrieve emails and pushed to the database.
Now I require to migrate to GSuite set-up whereby instead of host name the Gmail string has to be used:
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';

This throws connection error using fsockopen.

Could not make a connection to server , Error :
  php_network_getaddresses: getaddrinfo failed: Name or service not
  known (0)

Is there a work around whereby I can use this combination to get connected to the Gmail account using the fsockopen.
Since there's been a lot of custom work done with this existing setup in my application; I'm reluctant using imap_open as it would lead to re-work again on all aspects.
Any suggestion / help is highly appreciated.
Following is a rough code and below are the library functions being called:

        class Fetchmail extends Controller
        {
            function __construct()
            {
                parent::Controller();
                $this->load->library( "ImapMail" );
                ini_set( 'memory_limit', '128M' );
            }
            /*  Function to fetch mails from Inbox  */
            function fetchMail()
            {
                set_time_limit( 0 );
                /* connect to gmail */
                $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
                $username = 'someusername@gmail.com';
                $password = 'somepassword';
                if ( !$this->imapmail->open( $hostname ) )
                {
                    echo $this->imapmail->get_error();
                    break;
                }
                if ( !$this->imapmail->login( $username, $password ) )
                {
                    echo "Unable to login for " . $username . "";
                    echo $this->imapmail->get_error();
                }
                else
                {
                    /* pushing the mail contents to database */
                    echo "Success";
                }
                $this->imapmail->close();
            }
        }
        /***************** library functions *****************/
        /* Function is used to open connection */
        function open( $host = "", $port = "" )
        {
            if ( !empty( $host ) )
                $this->host = $host;
            if ( !empty( $port ) )
                $this->port = $port;
            return $this->open_connection();
        }
        /* Function to open the connection to the server */
        function open_connection()
        {
            if ( $this->state != "DISCONNECTED" )
            {
                $this->error = "Error : Already Connected!";
                return false;
            }
            if ( empty( $this->host ) || empty( $this->port ) )
            {
                $this->error = "Error : Either HOST or PORT is undifined!";
                return false;
            }
            $this->connection = fsockopen( $this->host, $this->port, $errno, $errstr );
            if ( !$this->connection )
            {
                $this->error = "Could not make a connection to server , Error : $errstr ($errno)";
                return false;
            }
            $respone     = $this->get_line();
            $this->state = "AUTHORIZATION";
            return true;
        }

