1

我使用 Chilkat php 扩展。而且我注意到 chilkat 方法 Connect 永远挂起。put_ReadTimeout()并且put_ConnectTimeout()不修复它。

我也通过 ssh 使用它。代码很简单,如下所示:

// $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);

我错过了任何无用的条件和其他代码。它是工作代码,有时它挂在 Connect 行。也许问题出在 SSH 中,也许 SSH 挂起?

如何解决?我还没有找到用 chilkat 函数解决的方法。另外我不想使用信号来停止 fetch 函数的执行。

我已经想通了。我做了很多测试,它挂在下一行: $this->imap->Connect($account->imap_server);

Chilkat 详细日志如下:

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.

日志结束于Received EOF on SSH channel.如你所见,我使用最后一个 Chilkat 版本。我的环境是 Ubuntu 服务器 18.04 64bit。PHP 7.2.2 ZTS。我在 Windows 上也遇到了同样的问题。

!!!同样重要的一点是,应用程序运行在多线程中,45 个线程。每个线程都有自己的 CkImap 对象并通过 ssh 连接到 imap。有时一些线程挂在连接到 imap 点。

这个挂怎么解决?

我找到了一些方法put_AbortCurrent。我可以用它来中止 Connect 方法吗?在我看来,下一个代码必须在连接超时后中止连接:

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

1 回答 1

1

使用 VerboseLogging 和 DebugLogFilePath 找出发生了什么。重现带有这些属性集的挂起。然后查看日志文件以了解挂起的位置(请参见下面的示例代码)。

此外,使用最新版本的 Chilkat 进行测试。如果您使用的是旧版本,也许很久以前就已经修复了。发行说明可在以下网址获得: 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";
于 2019-05-26T15:07:02.240 回答