2

当我尝试在 https url 上执行 curl 命令时,我不断收到“释放对象的校验和不正确”错误。这仅发生在我的 osx 开发人员机器上,当我在 ubuntu 服务器上执行相同的代码时,它不会发生。我还在其他 osx 设置上尝试过它,它在每台机器上都给出了相同的错误。

我正在运行 Mac OSX 10.7.4,并通过http://php-osx.liip.ch/安装了 php 5.4

这是我在控制台中遇到的错误的一部分:

Parent Process:  httpd [2228]

PlugIn Path:       /usr/local/php5/lib/libcurl.4.dylib
PlugIn Identifier: libcurl.4.dylib
PlugIn Version:    7.0.0 (compatibility 7.0.0)

Date/Time:       2012-07-31 09:30:50.602 +0200
OS Version:      Mac OS X 10.7.4 (11E53)
Report Version:  9

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
*** error for object 0x7fd15c8274f8: incorrect checksum for freed object - 
    object was probably modified after being freed.

导致此错误的代码如下:

function __doRequest($request, $location, $action, $version, $one_way = null)
{
    stream_wrapper_unregister('https');
    stream_wrapper_unregister('http');
    stream_wrapper_register('https', '<namespace>\\streamWrapperHttpAuth');
    stream_wrapper_register('http', '<namespace>\\streamWrapperHttpAuth');

    $headers = array(
        'User-Agent: PHP-SOAP', 'Content-Type: text/xml;charset=UTF-8', 
        'SOAPAction: "' . $action . '"', 
        'Content-Length: ' . strlen($request), 'Expect: 100-continue', 
        'Connection: Keep-Alive'
    );

    $this->__last_request_headers = $headers;
    $ch                           = curl_init($location);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);

    curl_setopt($ch, CURLOPT_USERPWD, $this->Username . ':' . $this->Password);
    curl_setopt($ch, CURLOPT_SSLVERSION, 3);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    //curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
    curl_setopt($ch, CURLOPT_CERTINFO, TRUE);

    $response = curl_exec($ch);

    if (($info = curl_getinfo($ch)) && $info['http_code'] == 200) {
        return $response;
    }
    else if ($info['http_code'] == 401) {
        throw new \Exception ('Access Denied', 401);
    }
    else if (curl_errno($ch) != 0) {
        throw new \Exception(curl_error($ch) . curl_errno($ch) . 
            $location, curl_errno($ch));
    }
    else {
        //throw new \Exception($response, $info['http_code']);
        return $response;
    }

    stream_wrapper_restore('https');
    stream_wrapper_restore('http');
}

错误在以下行中引发:'$response = curl_exec($ch);',当通过 http 而不是 https 调用 web 服务时它起作用了。

4

0 回答 0