Chilkat php imap Connect永远挂起

时间:2019-05-26 07:49:49

标签: php chilkat chilkat-email

我使用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);

我错过了任何无用的条件和其他代码。它正在工作,有时挂在连接线上。也许问题在于SSH,也许SSH挂起了?

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

我知道了。我做了很多测试,并挂在下一行:$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 64位。 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);

1 个答案:

答案 0 :(得分: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";