问:
Chilkat php imap Connect hangs forever
I use Chilkat php extension. And I have noticed that chilkat method Connect hangs forever. put_ReadTimeout() and put_ConnectTimeout() doesn't fix it.

Also I use it via ssh. The code is simple like this:

```<code>// $this->imap is a CKImap class

$this->imap->put_ConnectTimeout(10);
$this->imap->put_Ssl(true);
$this->imap->put_PeekMode(true);
$this->imap->put_Utf8(true);
$this->imap->put_VerboseLogging(true);
$this->imap->put_DebugLogFilePath('/var/www/logs/log_chilkat.txt');
$this->imap->SshOpenTunnel($proxy->ip, $proxy->port);
$this->imap->SshAuthenticatePw($proxy->username,$proxy->password);

// At this point it hangs forever
$this->imap->Connect($account->imap_server);
$this->imap->login($account->email, $account->password);
</code>```

I have missed any useless condition and other code. It is working code and sometimes it hangs at Connect line. Maybe problem is in SSH, maybe SSH hangs ?

How to solve it ? I have not found way to solve with chilkat functions. Also I don't want to use signals to stop fetch function execution.

I have figured it out. I have done a lot tests and it hangs at the next line:  $this->imap->Connect($account->imap_server);

Chilkat verbose logs are the following:

```SshOpenTunnel:
    DllDate: May 11 2019
    ChilkatVersion: 9.5.0.78
    UnlockPrefix: *******
    Architecture: Little Endian; 64-bit
    Language: Linux PHP
    VerboseLogging: 1
    sshTunnel:
        tunnelIdleTimeoutMs: 30000
        tunnelConnectTimeoutMs: 10000
        sshConnect:
            connectSocket:
                domainOrIpAddress: ******
                port: 22
                connectTimeoutMs: 10000
                connect_ipv6_or_ipv4:
                    This is an IPV4 numeric address.
                    Domain to IP address resolution not needed.
                    getAddressInfo:
                        (leaveContext)
                    findIpAddrInfo:
                        (leaveContext)
                    connecting to IPV4 address...
                    ipAddress: *****
                    createSocket:
                        Setting SO_SNDBUF size
                        sendBufSize: 262144
                        Setting SO_RCVBUF size
                        recvBufSize: 4194304
                        (leaveContext)
                    connect:
                        Waiting for the connect to complete...
                        connectTimeoutMs: 10000
                        ck_getsockname_ipv4:
                            (leaveContext)
                        myIP: *****
                        myPort: 48882
                        socket connect successful.
                        (leaveContext 261ms)
                    (leaveContext 261ms)
                (leaveContext 261ms)
            Established TCP/IP connection with SSH server
            Turning on TCP_NODELAY.
            (leaveContext 262ms)
        sshSetupConnection:
            clientIdentifier: SSH-2.0-PuTTY_Release_0.70
            Sending client identifier...
            Done sending client identifier.
            Reading server version...
            initialDataFromSshServer: SSH-2.0-OpenSSH_4.3

            serverVersion: SSH-2.0-OpenSSH_4.3
            build_kexInit:
                preferRsaHostKeyAlgorithm: 1
                (leaveContext)
            KeyExchangeAlgs:
                algorithm: diffie-hellman-group-exchange-sha1
                algorithm: diffie-hellman-group14-sha1
                algorithm: diffie-hellman-group1-sha1
                (leaveContext)
            HostKeyAlgs:
                algorithm: ssh-dss
                algorithm: ssh-rsa
                (leaveContext 1ms)
            EncCS:
                algorithm: aes128-ctr
                algorithm: aes192-ctr
                algorithm: aes256-ctr
                algorithm: arcfour256
                algorithm: arcfour128
                algorithm: aes128-cbc
                algorithm: 3des-cbc
                algorithm: blowfish-cbc
                algorithm: cast128-cbc
                algorithm: aes192-cbc
                algorithm: aes256-cbc
                algorithm: arcfour
                algorithm: rijndael-cbc@lysator.liu.se
                (leaveContext)
            EncSC:
                algorithm: aes128-ctr
                algorithm: aes192-ctr
                algorithm: aes256-ctr
                algorithm: arcfour256
                algorithm: arcfour128
                algorithm: aes128-cbc
                algorithm: 3des-cbc
                algorithm: blowfish-cbc
                algorithm: cast128-cbc
                algorithm: aes192-cbc
                algorithm: aes256-cbc
                algorithm: arcfour
                algorithm: rijndael-cbc@lysator.liu.se
                (leaveContext)
            MacCS:
                algorithm: hmac-md5
                algorithm: hmac-sha1
                algorithm: hmac-ripemd160
                algorithm: hmac-ripemd160@openssh.com
                algorithm: hmac-sha1-96
                algorithm: hmac-md5-96
                (leaveContext)
            MacSC:
                algorithm: hmac-md5
                algorithm: hmac-sha1
                algorithm: hmac-ripemd160
                algorithm: hmac-ripemd160@openssh.com
                algorithm: hmac-sha1-96
                algorithm: hmac-md5-96
                (leaveContext)
            CompCS:
                algorithm: none
                algorithm: zlib@openssh.com
                algorithm: zlib
                (leaveContext)
            CompSC:
                algorithm: none
                algorithm: zlib@openssh.com
                algorithm: zlib
                (leaveContext)
            LangCS:
                (leaveContext)
            LangSC:
                (leaveContext)
            ChosenIncomingEncryption: aes128-ctr
            ChosenOutgoingEncryptoin: aes128-ctr
            ChosenIncomingMac: hmac-sha1
            ChosenOutgoingMac: hmac-sha1
            ChosenIncomingCompression: zlib
            ChosenOutgoingCompression: zlib
            ChosenKexAlgorithm: diffie-hellman-group1-sha1
            choose_hostkey_algorithm:
                (leaveContext)
            ChosenHostKeyAlgorithm: ssh-rsa
            numBits: 128
            pbits: 1024
            Using Oakley Group 2.
            sendDhInit:
                create_E:
                    (leaveContext 7ms)
                Sent: SSH_MSG_KEXDH_INIT
                (leaveContext 7ms)
            computeExchangeHash:
                dhReplyMsgType: 31
                serverVersion: [SSH-2.0-OpenSSH_4.3]
                Using SHA-1 for Key Exchange Hash
                (leaveContext)
            verifyHostKey:
                rsaHostKeyVerify:
                    alg: ssh-rsa
                    hostKeyNumBits: 2048
                    verifyHashSsh:
                        Pkcs1_5_decode:
                            (leaveContext)
                        (leaveContext)
                    (leaveContext 1ms)
                RSA host key signature verification success.
                (leaveContext 1ms)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            Sending newkeys to server...
            Expecting newkeys from server...
            SSH Key Exchange Success.
            installNewKeys:
                m_isRekey: 0
                Outgoing compression is now zlib.
                Incoming compression is now zlib.
                Outgoing encryption is now AES 128 CTR
                initCrypt_aes2:
                    (leaveContext)
                initCrypt_aes2:
                    (leaveContext)
                (leaveContext)
            (leaveContext 934ms)
        (leaveContext 1197ms)
    Success.
    (leaveContext 1197ms)
SshAuthenticatePw:
    DllDate: May 11 2019
    ChilkatVersion: 9.5.0.78
    UnlockPrefix: *******
    Architecture: Little Endian; 64-bit
    Language: Linux PHP
    VerboseLogging: 1
    sshAuthenticatePw:
        sshAuthenticatePw:
            requestUserAuthService:
                sendServiceRequest:
                    svcName: ssh-userauth
                    SentServiceReq: ssh-userauth
                    (leaveContext)
                ssh-userauth service accepted.
                (leaveContext 735ms)
            sendUserAuthQuery:
                (leaveContext)
            AuthMethods: publickey,password
            passwordAuth:
                Sent login/password
                Password authentication successful.
                (leaveContext 593ms)
            (leaveContext 1762ms)
        (leaveContext 1762ms)
    Success.
    (leaveContext 1762ms)
Connect_Imap:
    DllDate: May 11 2019
    ChilkatVersion: 9.5.0.78
    UnlockPrefix: *****
    Architecture: Little Endian; 64-bit
    Language: Linux PHP
    VerboseLogging: 1
    connectInner:
        connectToImapServer:
            hostname: ******
            port: 993
            Closing the SSH channel, if it exists.
            sshCloseChannel:
                (leaveContext)
            socket2Connect:
                connect2:
                    hostname: ******
                    port: 993
                    ssl: True
                    sshOpenChannel:
                        Opening new SSH channel within SSH tunnel.
                        sshTransportOpenChannel:
                            channelType: direct-tcpip
                            clientChannel: 4815
                            clientInitialWindowSize: 2097152
                            clientMaxPacketSize: 32768
                            directTcpHost: ******
                            directTcpPort: 993
                            ck_getsockname_ipv4:
                                (leaveContext)
                            originatorIP: ****
                            originatorPort: 48882
                            Sent open channel request
                            ClientChannelNum: 4815
                            ServerChannelNum: 0
                            ServerInitialWindowSize: 2097152
                            serverMaxPacketSize: 32768
                            (leaveContext 1324ms)
                        [SSH] Direct TCP/IP channel successfully opened.
                        sshChannelNum: 4815
                        (leaveContext 1324ms)
                    Setting up SSL/TLS to run through an SSH tunnel...
                    Clearing TLS client certificates.
                    clientHandshake:
                        The client cert chain is NULL.
                        cacheClientCerts:
                            Cached TLS client certificates.
                            Client cert chain is NULL.
                            (leaveContext)
                        clientHandshake2:
                            createRandom:
                                (leaveContext)
                            sendClientHello:
                                TlsClientHello_buildMessage:
                                    (leaveContext)
                                sendHandshakeMessages:
                                    channelSendData2:
                                        (leaveContext)
                                    (leaveContext 1ms)
                                (leaveContext 1ms)
                            readHandshakeMessages:
                                processHandshakeRecord:
                                    processHandshakeMessage:
                                        processServerHello:
                                            negotiatedTlsVersion: TLS 1.2
                                            negotiatedCipherSuite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
                                            minAcceptableRsaKeySize: 1024
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext 3429ms)
                            readHandshakeMessages:
                                processHandshakeRecord:
                                    processHandshakeMessage:
                                        processIncomingCertificates:
                                            loadX509DerAlt:
                                                der_to_xml:
                                                    (leaveContext)
                                                (leaveContext)
                                            loadX509DerAlt:
                                                der_to_xml:
                                                    (leaveContext)
                                                (leaveContext)
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext 1ms)
                                (leaveContext 1409ms)
                            handleServerCert:
                                readHandshakeMessages:
                                    processHandshakeRecord:
                                        processHandshakeMessage:
                                            processServerKeyExchange:
                                                processEcDheKx:
                                                    (leaveContext)
                                                (leaveContext)
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext)
                            handleServerKeyExchange:
                                readHandshakeMessages:
                                    processHandshakeRecord:
                                        processHandshakeMessage:
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext 1ms)
                            buildClientKeyExchange:
                                buildClientKeyExchangeECDHE:
                                    verifyServerKeyExchange:
                                        getServerCertPublicKey:
                                            x509_getPublicKey:
                                                (leaveContext)
                                            (leaveContext)
                                        loadAnyDer:
                                            DecodeToAsn:
                                                (leaveContext)
                                            loadAnyAsn:
                                                loadRsaPkcs1Asn:
                                                    (leaveContext)
                                                (leaveContext)
                                            (leaveContext)
                                        composeVerifyData:
                                            (leaveContext)
                                        verifyHash:
                                            keyType: Public
                                            hashInSize: 32
                                            padding: PKCS v1.5
                                            Pkcs1_5_decode:
                                                (leaveContext)
                                            HashOid: 2.16.840.1.101.3.4.2.1
                                            (leaveContext 1ms)
                                        (leaveContext 1ms)
                                    Verified server key exchange.
                                    generateNewKey_ecc:
                                        loadCurveByName:
                                            name: secp256r1
                                            (leaveContext)
                                        genPubKey:
                                            pointMultiply:
                                                (leaveContext 6ms)
                                            (leaveContext 6ms)
                                        (leaveContext 6ms)
                                    exportEccPoint:
                                        (leaveContext)
                                    loadSshPubKey:
                                        loadCurveByName:
                                            name: secp256r1
                                            (leaveContext)
                                        loadEccPoint:
                                            (leaveContext)
                                        (leaveContext)
                                    sharedSecret:
                                        pointMultiply:
                                            (leaveContext 6ms)
                                        (leaveContext 6ms)
                                    (leaveContext 13ms)
                                (leaveContext 13ms)
                            sendClientKeyExchange:
                                sendHandshakeMessages:
                                    channelSendData2:
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext)
                            sendChangeCipherSpec:
                                channelSendData2:
                                    (leaveContext 1ms)
                                (leaveContext 1ms)
                            derive_keys:
                                initCrypt_aes2:
                                    (leaveContext)
                                initCrypt_aes2:
                                    (leaveContext)
                                (leaveContext)
                            buildFinished:
                                calc_finished:
                                    (leaveContext)
                                (leaveContext)
                            sendHandshakeMessages:
                                channelSendData2:
                                    (leaveContext)
                                (leaveContext)
                            readHandshakeMessages:
                                Returning because of channel EOF
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                Received EOF on SSH channel.
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
```

<p>Logs just ends at <code>Received EOF on SSH channel.</code> As you see I use last Chilkat version. My environment is Ubuntu server 18.04 64bit. PHP 7.2.2 ZTS. Also the same problem I had on Windows. </p>

<p>!!! Also important notice, the application is running in multithreading, 45 threads. Each thread has own CkImap object and performs connecting to imap via ssh. And sometimes some thread hangs at Connect to imap point.</p>

<p>How to solve this hanging ? </p>

<p>I have found some method <code>put_AbortCurrent</code>. May I use it to abort Connect method? In my opinion the next code has to abort Connect after connect timeout:</p>

```        $this->imap->put_AbortCurrent(true);
        $connectedToImap = $this->imap->Connect($account->imap_server);
        $this->imap->put_AbortCurrent(false);
```

答:
Use VerboseLogging and DebugLogFilePath to find out what happened.  Reproduce the hang w/ these properties set.  Then look at the log file to see where the hang occurred (see the sample code below).

Also, test using the latest version of Chilkat.  If you are using an old version, perhaps something was fixed long ago.   Release notes are available at:  http://cknotes.com/chilkat-v9-5-0-78-release-notes/

```<code>
    $imap = new CkImap();

    $imap->put_VerboseLogging(true);
    $imap->put_DebugLogFilePath('someDir/imapDebugLog.txt');
    $imap->put_ReadTimeout(10);

    // ...

    // Some UID...
    $msgId = 123;
    $bUid = true;
    $strMime = $imap->fetchSingleAsMime($msgId,$bUid);
    if ($imap->get_LastMethodSuccess() != true) {
        print $imap->lastErrorText() . "\n";
        exit;
    }

    print $strMime . "\n";
</code>```

Title: Chilkat php imap Connect hangs forever

Body:
I use Chilkat php extension. And I have noticed that chilkat method Connect hangs forever. put_ReadTimeout() and put_ConnectTimeout() doesn't fix it.

Also I use it via ssh. The code is simple like this:

// $this->imap is a CKImap class

$this->imap->put_ConnectTimeout(10);
$this->imap->put_Ssl(true);
$this->imap->put_PeekMode(true);
$this->imap->put_Utf8(true);
$this->imap->put_VerboseLogging(true);
$this->imap->put_DebugLogFilePath('/var/www/logs/log_chilkat.txt');
$this->imap->SshOpenTunnel($proxy->ip, $proxy->port);
$this->imap->SshAuthenticatePw($proxy->username,$proxy->password);

// At this point it hangs forever
$this->imap->Connect($account->imap_server);
$this->imap->login($account->email, $account->password);

I have missed any useless condition and other code. It is working code and sometimes it hangs at Connect line. Maybe problem is in SSH, maybe SSH hangs ?

How to solve it ? I have not found way to solve with chilkat functions. Also I don't want to use signals to stop fetch function execution.

I have figured it out. I have done a lot tests and it hangs at the next line:  $this->imap->Connect($account->imap_server);

Chilkat verbose logs are the following:

SshOpenTunnel:
    DllDate: May 11 2019
    ChilkatVersion: 9.5.0.78
    UnlockPrefix: *******
    Architecture: Little Endian; 64-bit
    Language: Linux PHP
    VerboseLogging: 1
    sshTunnel:
        tunnelIdleTimeoutMs: 30000
        tunnelConnectTimeoutMs: 10000
        sshConnect:
            connectSocket:
                domainOrIpAddress: ******
                port: 22
                connectTimeoutMs: 10000
                connect_ipv6_or_ipv4:
                    This is an IPV4 numeric address.
                    Domain to IP address resolution not needed.
                    getAddressInfo:
                        (leaveContext)
                    findIpAddrInfo:
                        (leaveContext)
                    connecting to IPV4 address...
                    ipAddress: *****
                    createSocket:
                        Setting SO_SNDBUF size
                        sendBufSize: 262144
                        Setting SO_RCVBUF size
                        recvBufSize: 4194304
                        (leaveContext)
                    connect:
                        Waiting for the connect to complete...
                        connectTimeoutMs: 10000
                        ck_getsockname_ipv4:
                            (leaveContext)
                        myIP: *****
                        myPort: 48882
                        socket connect successful.
                        (leaveContext 261ms)
                    (leaveContext 261ms)
                (leaveContext 261ms)
            Established TCP/IP connection with SSH server
            Turning on TCP_NODELAY.
            (leaveContext 262ms)
        sshSetupConnection:
            clientIdentifier: SSH-2.0-PuTTY_Release_0.70
            Sending client identifier...
            Done sending client identifier.
            Reading server version...
            initialDataFromSshServer: SSH-2.0-OpenSSH_4.3

            serverVersion: SSH-2.0-OpenSSH_4.3
            build_kexInit:
                preferRsaHostKeyAlgorithm: 1
                (leaveContext)
            KeyExchangeAlgs:
                algorithm: diffie-hellman-group-exchange-sha1
                algorithm: diffie-hellman-group14-sha1
                algorithm: diffie-hellman-group1-sha1
                (leaveContext)
            HostKeyAlgs:
                algorithm: ssh-dss
                algorithm: ssh-rsa
                (leaveContext 1ms)
            EncCS:
                algorithm: aes128-ctr
                algorithm: aes192-ctr
                algorithm: aes256-ctr
                algorithm: arcfour256
                algorithm: arcfour128
                algorithm: aes128-cbc
                algorithm: 3des-cbc
                algorithm: blowfish-cbc
                algorithm: cast128-cbc
                algorithm: aes192-cbc
                algorithm: aes256-cbc
                algorithm: arcfour
                algorithm: rijndael-cbc@lysator.liu.se
                (leaveContext)
            EncSC:
                algorithm: aes128-ctr
                algorithm: aes192-ctr
                algorithm: aes256-ctr
                algorithm: arcfour256
                algorithm: arcfour128
                algorithm: aes128-cbc
                algorithm: 3des-cbc
                algorithm: blowfish-cbc
                algorithm: cast128-cbc
                algorithm: aes192-cbc
                algorithm: aes256-cbc
                algorithm: arcfour
                algorithm: rijndael-cbc@lysator.liu.se
                (leaveContext)
            MacCS:
                algorithm: hmac-md5
                algorithm: hmac-sha1
                algorithm: hmac-ripemd160
                algorithm: hmac-ripemd160@openssh.com
                algorithm: hmac-sha1-96
                algorithm: hmac-md5-96
                (leaveContext)
            MacSC:
                algorithm: hmac-md5
                algorithm: hmac-sha1
                algorithm: hmac-ripemd160
                algorithm: hmac-ripemd160@openssh.com
                algorithm: hmac-sha1-96
                algorithm: hmac-md5-96
                (leaveContext)
            CompCS:
                algorithm: none
                algorithm: zlib@openssh.com
                algorithm: zlib
                (leaveContext)
            CompSC:
                algorithm: none
                algorithm: zlib@openssh.com
                algorithm: zlib
                (leaveContext)
            LangCS:
                (leaveContext)
            LangSC:
                (leaveContext)
            ChosenIncomingEncryption: aes128-ctr
            ChosenOutgoingEncryptoin: aes128-ctr
            ChosenIncomingMac: hmac-sha1
            ChosenOutgoingMac: hmac-sha1
            ChosenIncomingCompression: zlib
            ChosenOutgoingCompression: zlib
            ChosenKexAlgorithm: diffie-hellman-group1-sha1
            choose_hostkey_algorithm:
                (leaveContext)
            ChosenHostKeyAlgorithm: ssh-rsa
            numBits: 128
            pbits: 1024
            Using Oakley Group 2.
            sendDhInit:
                create_E:
                    (leaveContext 7ms)
                Sent: SSH_MSG_KEXDH_INIT
                (leaveContext 7ms)
            computeExchangeHash:
                dhReplyMsgType: 31
                serverVersion: [SSH-2.0-OpenSSH_4.3]
                Using SHA-1 for Key Exchange Hash
                (leaveContext)
            verifyHostKey:
                rsaHostKeyVerify:
                    alg: ssh-rsa
                    hostKeyNumBits: 2048
                    verifyHashSsh:
                        Pkcs1_5_decode:
                            (leaveContext)
                        (leaveContext)
                    (leaveContext 1ms)
                RSA host key signature verification success.
                (leaveContext 1ms)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            calculateKey:
                (leaveContext)
            Sending newkeys to server...
            Expecting newkeys from server...
            SSH Key Exchange Success.
            installNewKeys:
                m_isRekey: 0
                Outgoing compression is now zlib.
                Incoming compression is now zlib.
                Outgoing encryption is now AES 128 CTR
                initCrypt_aes2:
                    (leaveContext)
                initCrypt_aes2:
                    (leaveContext)
                (leaveContext)
            (leaveContext 934ms)
        (leaveContext 1197ms)
    Success.
    (leaveContext 1197ms)
SshAuthenticatePw:
    DllDate: May 11 2019
    ChilkatVersion: 9.5.0.78
    UnlockPrefix: *******
    Architecture: Little Endian; 64-bit
    Language: Linux PHP
    VerboseLogging: 1
    sshAuthenticatePw:
        sshAuthenticatePw:
            requestUserAuthService:
                sendServiceRequest:
                    svcName: ssh-userauth
                    SentServiceReq: ssh-userauth
                    (leaveContext)
                ssh-userauth service accepted.
                (leaveContext 735ms)
            sendUserAuthQuery:
                (leaveContext)
            AuthMethods: publickey,password
            passwordAuth:
                Sent login/password
                Password authentication successful.
                (leaveContext 593ms)
            (leaveContext 1762ms)
        (leaveContext 1762ms)
    Success.
    (leaveContext 1762ms)
Connect_Imap:
    DllDate: May 11 2019
    ChilkatVersion: 9.5.0.78
    UnlockPrefix: *****
    Architecture: Little Endian; 64-bit
    Language: Linux PHP
    VerboseLogging: 1
    connectInner:
        connectToImapServer:
            hostname: ******
            port: 993
            Closing the SSH channel, if it exists.
            sshCloseChannel:
                (leaveContext)
            socket2Connect:
                connect2:
                    hostname: ******
                    port: 993
                    ssl: True
                    sshOpenChannel:
                        Opening new SSH channel within SSH tunnel.
                        sshTransportOpenChannel:
                            channelType: direct-tcpip
                            clientChannel: 4815
                            clientInitialWindowSize: 2097152
                            clientMaxPacketSize: 32768
                            directTcpHost: ******
                            directTcpPort: 993
                            ck_getsockname_ipv4:
                                (leaveContext)
                            originatorIP: ****
                            originatorPort: 48882
                            Sent open channel request
                            ClientChannelNum: 4815
                            ServerChannelNum: 0
                            ServerInitialWindowSize: 2097152
                            serverMaxPacketSize: 32768
                            (leaveContext 1324ms)
                        [SSH] Direct TCP/IP channel successfully opened.
                        sshChannelNum: 4815
                        (leaveContext 1324ms)
                    Setting up SSL/TLS to run through an SSH tunnel...
                    Clearing TLS client certificates.
                    clientHandshake:
                        The client cert chain is NULL.
                        cacheClientCerts:
                            Cached TLS client certificates.
                            Client cert chain is NULL.
                            (leaveContext)
                        clientHandshake2:
                            createRandom:
                                (leaveContext)
                            sendClientHello:
                                TlsClientHello_buildMessage:
                                    (leaveContext)
                                sendHandshakeMessages:
                                    channelSendData2:
                                        (leaveContext)
                                    (leaveContext 1ms)
                                (leaveContext 1ms)
                            readHandshakeMessages:
                                processHandshakeRecord:
                                    processHandshakeMessage:
                                        processServerHello:
                                            negotiatedTlsVersion: TLS 1.2
                                            negotiatedCipherSuite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
                                            minAcceptableRsaKeySize: 1024
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext 3429ms)
                            readHandshakeMessages:
                                processHandshakeRecord:
                                    processHandshakeMessage:
                                        processIncomingCertificates:
                                            loadX509DerAlt:
                                                der_to_xml:
                                                    (leaveContext)
                                                (leaveContext)
                                            loadX509DerAlt:
                                                der_to_xml:
                                                    (leaveContext)
                                                (leaveContext)
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext 1ms)
                                (leaveContext 1409ms)
                            handleServerCert:
                                readHandshakeMessages:
                                    processHandshakeRecord:
                                        processHandshakeMessage:
                                            processServerKeyExchange:
                                                processEcDheKx:
                                                    (leaveContext)
                                                (leaveContext)
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext)
                            handleServerKeyExchange:
                                readHandshakeMessages:
                                    processHandshakeRecord:
                                        processHandshakeMessage:
                                            (leaveContext)
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext 1ms)
                            buildClientKeyExchange:
                                buildClientKeyExchangeECDHE:
                                    verifyServerKeyExchange:
                                        getServerCertPublicKey:
                                            x509_getPublicKey:
                                                (leaveContext)
                                            (leaveContext)
                                        loadAnyDer:
                                            DecodeToAsn:
                                                (leaveContext)
                                            loadAnyAsn:
                                                loadRsaPkcs1Asn:
                                                    (leaveContext)
                                                (leaveContext)
                                            (leaveContext)
                                        composeVerifyData:
                                            (leaveContext)
                                        verifyHash:
                                            keyType: Public
                                            hashInSize: 32
                                            padding: PKCS v1.5
                                            Pkcs1_5_decode:
                                                (leaveContext)
                                            HashOid: 2.16.840.1.101.3.4.2.1
                                            (leaveContext 1ms)
                                        (leaveContext 1ms)
                                    Verified server key exchange.
                                    generateNewKey_ecc:
                                        loadCurveByName:
                                            name: secp256r1
                                            (leaveContext)
                                        genPubKey:
                                            pointMultiply:
                                                (leaveContext 6ms)
                                            (leaveContext 6ms)
                                        (leaveContext 6ms)
                                    exportEccPoint:
                                        (leaveContext)
                                    loadSshPubKey:
                                        loadCurveByName:
                                            name: secp256r1
                                            (leaveContext)
                                        loadEccPoint:
                                            (leaveContext)
                                        (leaveContext)
                                    sharedSecret:
                                        pointMultiply:
                                            (leaveContext 6ms)
                                        (leaveContext 6ms)
                                    (leaveContext 13ms)
                                (leaveContext 13ms)
                            sendClientKeyExchange:
                                sendHandshakeMessages:
                                    channelSendData2:
                                        (leaveContext)
                                    (leaveContext)
                                (leaveContext)
                            sendChangeCipherSpec:
                                channelSendData2:
                                    (leaveContext 1ms)
                                (leaveContext 1ms)
                            derive_keys:
                                initCrypt_aes2:
                                    (leaveContext)
                                initCrypt_aes2:
                                    (leaveContext)
                                (leaveContext)
                            buildFinished:
                                calc_finished:
                                    (leaveContext)
                                (leaveContext)
                            sendHandshakeMessages:
                                channelSendData2:
                                    (leaveContext)
                                (leaveContext)
                            readHandshakeMessages:
                                Returning because of channel EOF
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                Received EOF on SSH channel.
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.
                                Received CHANNEL REQUEST message
                                channelNum: 4815
                                requestType: keepalive@openssh.com
                                wantReply: 1
                                Received EOF on SSH channel.

Logs just ends at Received EOF on SSH channel. As you see I use last Chilkat version. My environment is Ubuntu server 18.04 64bit. PHP 7.2.2 ZTS. Also the same problem I had on Windows.

!!! Also important notice, the application is running in multithreading, 45 threads. Each thread has own CkImap object and performs connecting to imap via ssh. And sometimes some thread hangs at Connect to imap point.

How to solve this hanging ?

I have found some method put_AbortCurrent. May I use it to abort Connect method? In my opinion the next code has to abort Connect after connect timeout:

        $this->imap->put_AbortCurrent(true);
        $connectedToImap = $this->imap->Connect($account->imap_server);
        $this->imap->put_AbortCurrent(false);

Body:
Use VerboseLogging and DebugLogFilePath to find out what happened.  Reproduce the hang w/ these properties set.  Then look at the log file to see where the hang occurred (see the sample code below).

Also, test using the latest version of Chilkat.  If you are using an old version, perhaps something was fixed long ago.   Release notes are available at:  http://cknotes.com/chilkat-v9-5-0-78-release-notes/

    $imap = new CkImap();

    $imap->put_VerboseLogging(true);
    $imap->put_DebugLogFilePath('someDir/imapDebugLog.txt');
    $imap->put_ReadTimeout(10);

    // ...

    // Some UID...
    $msgId = 123;
    $bUid = true;
    $strMime = $imap->fetchSingleAsMime($msgId,$bUid);
    if ($imap->get_LastMethodSuccess() != true) {
        print $imap->lastErrorText() . "\n";
        exit;
    }

    print $strMime . "\n";


来源: stackexchange

问:
How to display my values in props array horizontally
In my React project I have to take an array from parent component and print it in child component(PrintHorizontal) horizontally.

I am using map function which renders my values vertically so I wrote join to combine array values but I am getting different value. Print is my child component

```<code>props.values=[
   {
    id:1,
    x:1
   },
   {
    id:1,
    x:1
   }
 ]

PrintHorizontal Component:
const PrintHorizontal = props => {
let list=props.values.map(value => {
    return <Print key={value.id} data={value.x} />
 });
return (
    <div>
        {list.join(' , ')}
    </div>
)
}

Print Component:
const Print = props => {
    return (
        <div>
            <Avatar>{props.data}</Avatar>  //Avatar is a component imported from materialUI
        </div>
    )
}
</code>```

I expect run values would be printed horizontally instead I am getting
[object Object],[object Object]

答:
```<code><!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        main = () => {
            const arr = [1, 2, 3, 4];
            const list = arr.map(item => {
                const node = document.createElement('span');
                node.innerHTML = item * 2;
                node.style.margin = '20px';
                return node;
            });

            list.forEach(element => {
                document.getElementById("target").appendChild(element)
            })
        }
    </script>
</head>

<body onload="main()">
    <div id="target"></div>
</body>

</html>
</code>```

ContentLicense: CC BY-SA 4.0

Body:
In my React project I have to take an array from parent component and print it in child component(PrintHorizontal) horizontally.

I am using map function which renders my values vertically so I wrote join to combine array values but I am getting different value. Print is my child component

props.values=[
   {
    id:1,
    x:1
   },
   {
    id:1,
    x:1
   }
 ]

PrintHorizontal Component:
const PrintHorizontal = props => {
let list=props.values.map(value => {
    return <Print key={value.id} data={value.x} />
 });
return (

        {list.join(' , ')}

)
}

Print Component:
const Print = props => {
    return (

            <Avatar>{props.data}</Avatar>  //Avatar is a component imported from materialUI

    )
}

I expect run values would be printed horizontally instead I am getting
[object Object],[object Object]


问:
find similar rows in a text file in unix system
I have a file named tt.txt and the contents of this file is as follows:

```<code>fdgs
jhds
fdgs
</code>```

I am trying to get the similar row as the output in a text file.

my expected output is:

```<code>fdgs
fdgs
</code>```

to do so, I used this command:

```<code>uniq -u tt.txt > output.txt
</code>```

but it returns:

```<code>fdgs
jhds
fdgs
</code>```

do you know how to fix it?

答:
If by similar row you mean the row with the same content.

From the uniq manpage the uniq command would only filter the adjacent matching lines from the repeated lines. So you need to sort the input first and used -D option to print all duplicated lines like below. However -D options is limited to the GNU implementation, and doing this would print the output in different order from the input.

sort tt.txt  | uniq -D

If you want the output to be in the same order you need to remember the input line number and sort the line number again like this

cat -n tt.txt  | sort -k 2 | uniq -f 1 -D | sort -k 1,1   | sed 's/\s+[0-9]+\s+//'

cat -n would print the content with the line number

sort -k 2 would sort the input starting at 2rd column

uniq -f 1 would ignore the first column

sort -k1,1 would sort the the output back by the original line number

sed 's/\s+[0-9]+\s+//' would delete the first column with line number

uniq -u command would output only the unique input line, which is completely opposite as what you want.

Body:
I have a file named tt.txt and the contents of this file is as follows:

fdgs
jhds
fdgs

I am trying to get the similar row as the output in a text file.

my expected output is:

fdgs
fdgs

to do so, I used this command:

uniq -u tt.txt > output.txt

but it returns:

fdgs
jhds
fdgs

do you know how to fix it?


问:
How To Add MultipleChoiceField To Django Admin?
I have a CharField field in my model. I want to display it as a MultipleChoiceField widget in the Django admin site. models.py:

class Product(models.Model):
    ...
    categories = models.CharField()
    ...
```
<p>I've created a custom form widget in <strong>forms.py</strong>:</p>
<pre class="lang-py prettyprint-override"><code>from django import forms

CATEGORIES_LIST = [
    ('for_him', 'For Him'),
    ('for_her', 'For Her'),
    ('for_kids', 'For Kids'),
]

class Categories(forms.Form):
    categories = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=CATEGORIES_LIST,
    )
</code>```

Not quite sure what to do next. How do I connect this widget with Django Admin for my Product model? Thanks in advance for your help!

答:
What you are trying to do is not that straight forward using a CharField and putting multiple options in it so you must first find a way to serialize and restore your data to the model take a look here.

if you are on a postgres database you could do it this way (thanks to postgres array fields you don't have the serializing and restoring data headache)

```<code>from django.contrib.postgres.fields import ArrayField
class ChoiceArrayField(ArrayField):
    """
    A field that allows us to store an array of choices.

    Uses Django 1.9's postgres ArrayField
    and a MultipleChoiceField for its formfield.

    Usage:

        choices = ChoiceArrayField(models.CharField(max_length=..., choices=(...,)), default=[...])
    """

    def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.MultipleChoiceField,
            'choices': self.base_field.choices,
        }
        defaults.update(kwargs)
        return super(ArrayField, self).formfield(**defaults)
</code>```

and then you can use ChoiceArrayField on your model

Update:

So to use this on your model you can do it like this:

```<code>class Product(models.Model):
    categories = ChoiceArrayField(max_length=8, choices=CATEGORIES_LIST, default=['for_him', 'for_her'])
</code>```

Body:
I have a CharField field in my model. I want to display it as a MultipleChoiceField widget in the Django admin site. models.py:

class Product(models.Model):
    ...
    categories = models.CharField()
    ...

I've created a custom form widget in forms.py:

from django import forms

CATEGORIES_LIST = [
    ('for_him', 'For Him'),
    ('for_her', 'For Her'),
    ('for_kids', 'For Kids'),
]

class Categories(forms.Form):
    categories = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=CATEGORIES_LIST,
    )

Not quite sure what to do next. How do I connect this widget with Django Admin for my Product model? Thanks in advance for your help!

Body:
What you are trying to do is not that straight forward using a CharField and putting multiple options in it so you must first find a way to serialize and restore your data to the model take a look here.

if you are on a postgres database you could do it this way (thanks to postgres array fields you don't have the serializing and restoring data headache)

from django.contrib.postgres.fields import ArrayField
class ChoiceArrayField(ArrayField):
    """
    A field that allows us to store an array of choices.

    Uses Django 1.9's postgres ArrayField
    and a MultipleChoiceField for its formfield.

    Usage:

        choices = ChoiceArrayField(models.CharField(max_length=..., choices=(...,)), default=[...])
    """

    def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.MultipleChoiceField,
            'choices': self.base_field.choices,
        }
        defaults.update(kwargs)
        return super(ArrayField, self).formfield(**defaults)

and then you can use ChoiceArrayField on your model

Update:

So to use this on your model you can do it like this:

class Product(models.Model):
    categories = ChoiceArrayField(max_length=8, choices=CATEGORIES_LIST, default=['for_him', 'for_her'])


问:
Can't install psycopg2 package through pip install on MacOS
I am working on a project for one of my lectures and I need to download the package psycopg2 in order to work with the postgresql database in use. Unfortunately, when I try to pip install psycopg2 the following error pops up:

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1
```

Why is this happening?

答: Old, but for folks using pipenv, I resolved this issue by looking at my dependency graph pipenv graph --reverse and noticing it required psycopg2-binary==2.8.2.  Running pipenv install psycopg2-binary resolved the issue.

Body:
I am working on a project for one of my lectures and I need to download the package psycopg2 in order to work with the postgresql database in use. Unfortunately, when I try to pip install psycopg2 the following error pops up:

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1

Why is this happening?


问:
How get admin privileges?
I have a question and its long time im looking for answer, i wrote a program and i need to know with which installer i can configure Windows 7 to run my program as Administrator? my program will come up with windows starting and i want it to run as Administrator. I included the manifest to my program and compiled it but windows will ask for every time my program want to be executed it would be better if there will be any possibility just to ask once for admin privileges.
Someone told me with an installer you dont need to include manifest to your program and there will be some options to ask just once for admin privilege. can anyone help me with this?
Thank you.</p>

答: You need to somehow configure your application to run under the local system account. Usually this is done through a scheduled task or a Windows service.</p>

ContentLicense: CC BY-SA 3.0

Title: How get admin privileges?


问:
Matlab: Solve 2nd order ODE using anonymous function
To solve ODE below with matlab

```<code>t = 0:.01:20;
x0 = [0 0]';
xdot = @(t,x) [0 1; 0 0] * x;
ode45(@(t,x) xdot(x(1), x(2)),t,x0)
</code>```

I get this error:

Error using odearguments (line 91) @(T,X)XDOT(X(1),X(2)) must return a
  column vector.

答:
Your x0 is a 2 by 1 matrix, precise this in your function handle

```<code>xdot = @(t,x) [0 1; 0 0] * x; ---> xdot = @(t,x) [0 1; 0 0] * [x(1);x(2)];
</code>```

since xdot is already defined as a function you don't need @ to pass it in ode45

The code is as follow

```<code>t = 0:.01:20;
x0 = [0 0]';
xdot = @(t,x) [0 1; 0 0] * [x(1);x(2)];
ode45(xdot,t,x0)
</code>```

Body:
To solve ODE below with matlab

t = 0:.01:20;
x0 = [0 0]';
xdot = @(t,x) [0 1; 0 0] * x;
ode45(@(t,x) xdot(x(1), x(2)),t,x0)

I get this error:

Error using odearguments (line 91) @(T,X)XDOT(X(1),X(2)) must return a
  column vector.

Body:
Your x0 is a 2 by 1 matrix, precise this in your function handle

xdot = @(t,x) [0 1; 0 0] * x; ---> xdot = @(t,x) [0 1; 0 0] * [x(1);x(2)];

since xdot is already defined as a function you don't need @ to pass it in ode45

The code is as follow

t = 0:.01:20;
x0 = [0 0]';
xdot = @(t,x) [0 1; 0 0] * [x(1);x(2)];
ode45(xdot,t,x0)


问:
Cannot create ArrayList with ResultSet
I'm trying to create an ArrayList based on the ResultSet. Using the while loop to iterate through all the rows I can get only the first row (With rs.next() and rs.first()) as well as the last one (rs.last()).

```<code>public ArrayList retrieveFromDb(Statement myStmt){

    try{
        ArrayList<String> inner = new ArrayList<>();
        String query = "SELECT * FROM product";
        ResultSet rs = myStmt.executeQuery(query);

        while(rs.next()){
            System.out.println(rs.getString("barcode"));
            inner.add(rs.getString("barcode"));
            System.out.println("done");

        return inner;
        }

    } catch (SQLException ex) {
        Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
</code>```

What I need is for the ArrayList to get the information from all the rows.

UPDATE: It looks like I failed to properly return the list by returning it too early (as pointed out in the answer below.)

答:
You are returning your list too early. Move your return statement to the end.

Reread the Oracle Tutorial, Retrieving and Modifying Values from Result Sets.

Also, close your result set when finished using it.

We can make your returned list a more general List rather than ArrayList, and more specifically of type String.

```<code>public List< String > retrieveFromDb( Statement myStmt ){
    ArrayList<String> list = new ArrayList<>() ;

    try{
        String query = "SELECT * FROM product ;" ;
        ResultSet rs = myStmt.executeQuery( query ) ;

        while( rs.next() ){  // Looping the rows of the result set: first row, second row, third, fourth, and so on.
            String barcode = rs.getString( "barcode" ) ;
            list.add( rs.getString( "barcode" ) );
        }

    } catch (SQLException ex) {
        Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if( Objects.nonNull( rs ) ) {
            rs.close() ;  // <--- Best to close your result set when done.
        }
    }

    return list ;
}
</code>```

Even better, use try-with-resources to automatically close your result set.

```<code>public List< String > retrieveFromDb( Statement myStmt ){
    ArrayList<String> list = new ArrayList<>() ;
    String query = "SELECT * FROM product ;" ;

    try (
        ResultSet rs = myStmt.executeQuery( query ) ;
    )
    {
        while( rs.next() ){  // Looping the rows of the result set: first row, second row, third, fourth, and so on.
            String barcode = rs.getString( "barcode" ) ;
            list.add( rs.getString( "barcode" ) );
        }

    } catch (SQLException ex) {
        Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
    }

    return list ;
}
</code>```

Tip: I recommend always terminating your SQL statements properly, with a semicolon. You may get away without it, but making it a habit can prevent problems in the long run.

Title: Cannot create ArrayList with ResultSet

Body:
I'm trying to create an ArrayList based on the ResultSet. Using the while loop to iterate through all the rows I can get only the first row (With rs.next() and rs.first()) as well as the last one (rs.last()).

public ArrayList retrieveFromDb(Statement myStmt){

    try{
        ArrayList<String> inner = new ArrayList<>();
        String query = "SELECT * FROM product";
        ResultSet rs = myStmt.executeQuery(query);

        while(rs.next()){
            System.out.println(rs.getString("barcode"));
            inner.add(rs.getString("barcode"));
            System.out.println("done");

        return inner;
        }

    } catch (SQLException ex) {
        Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

What I need is for the ArrayList to get the information from all the rows.

UPDATE: It looks like I failed to properly return the list by returning it too early (as pointed out in the answer below.)

Body:
You are returning your list too early. Move your return statement to the end.

Reread the Oracle Tutorial, Retrieving and Modifying Values from Result Sets.

Also, close your result set when finished using it.

We can make your returned list a more general List rather than ArrayList, and more specifically of type String.

public List< String > retrieveFromDb( Statement myStmt ){
    ArrayList<String> list = new ArrayList<>() ;

    try{
        String query = "SELECT * FROM product ;" ;
        ResultSet rs = myStmt.executeQuery( query ) ;

        while( rs.next() ){  // Looping the rows of the result set: first row, second row, third, fourth, and so on.
            String barcode = rs.getString( "barcode" ) ;
            list.add( rs.getString( "barcode" ) );
        }

    } catch (SQLException ex) {
        Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if( Objects.nonNull( rs ) ) {
            rs.close() ;  // <--- Best to close your result set when done.
        }
    }

    return list ;
}

Even better, use try-with-resources to automatically close your result set.

public List< String > retrieveFromDb( Statement myStmt ){
    ArrayList<String> list = new ArrayList<>() ;
    String query = "SELECT * FROM product ;" ;

    try (
        ResultSet rs = myStmt.executeQuery( query ) ;
    )
    {
        while( rs.next() ){  // Looping the rows of the result set: first row, second row, third, fourth, and so on.
            String barcode = rs.getString( "barcode" ) ;
            list.add( rs.getString( "barcode" ) );
        }

    } catch (SQLException ex) {
        Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
    }

    return list ;
}

Tip: I recommend always terminating your SQL statements properly, with a semicolon. You may get away without it, but making it a habit can prevent problems in the long run.


问:
Cache the user identity
There is any way to cache the identity? In my code, I have multiple DB queries about user profile. I think should be a way to cache it to prevent multiple requests.</p>

```<code>yii::$app->user->identity
</code>```

答:
Identity should already be cached in context of request (only one query per request).

If you want to cache identity between requests, you can implement caching in findIdentity() implementation of class used as $identityClass of your user component:

```<code>public static function findIdentity($id) {
    return static::find()->cache(60)->where(['id' => $id])->one();
}
</code>```

But usually it is not worth the trouble - one simple query using primary key should be really fast, caching it will not give you measurable performance boost, while it may create some weird cache-related bugs.

Title: Cache the user identity

Body:
There is any way to cache the identity? In my code, I have multiple DB queries about user profile. I think should be a way to cache it to prevent multiple requests.

yii::$app->user->identity

Body:
Identity should already be cached in context of request (only one query per request).

If you want to cache identity between requests, you can implement caching in findIdentity() implementation of class used as $identityClass of your user component:

public static function findIdentity($id) {
    return static::find()->cache(60)->where(['id' => $id])->one();
}

But usually it is not worth the trouble - one simple query using primary key should be really fast, caching it will not give you measurable performance boost, while it may create some weird cache-related bugs.