cURL错误2:在多句柄中已经使用的简单句柄(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)Google客户端访问令牌

我在我的网站上通过Googleclient使用google身份验证。当我尝试使用Auth代码获取Google访问令牌时,出现以下错误。

$accessToken = $client->fetchaccessTokenWithAuthCode($_GET['code'])

这是错误

cURL error 2: easy handle already used in multi handle (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

请帮助我。

henshui22 回答:cURL错误2:在多句柄中已经使用的简单句柄(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)Google客户端访问令牌

我在这里发布我的解决方案。

问题:

我的情况是,我的服务器自动更新某些内容时,会影响某些功能来处理多个cUrl请求。

解决方案:

我正在使用 Yii Framework ,并且在我的项目中使用 guzzlehttp 供应商。这个模块提出了这个问题。所以我评论了一段代码来解决这个问题。

打开文件。 vendor / guzzlehttp / guzzle / src / Handler / CurlFactory.php

转到功能发布

并注释以下几行。

if (count($this->handles) >= $this->maxHandles) {
   curl_close($resource);
} else {
   // Remove all callback functions as they can hold onto references
   // and are not cleaned up by curl_reset. Using curl_setopt_array
   // does not work for some reason,so removing each one
   // individually.
   curl_setopt($resource,CURLOPT_HEADERFUNCTION,null);
   curl_setopt($resource,CURLOPT_READFUNCTION,CURLOPT_WRITEFUNCTION,CURLOPT_PROGRESSFUNCTION,null);
   curl_reset($resource);
   $this->handles[] = $resource;
}

并添加以下行代替

curl_close($resource);

应用解决方案后,请参阅完整的功能。

public function release(EasyHandle $easy)
{
    $resource = $easy->handle;
    unset($easy->handle);

    /*if (count($this->handles) >= $this->maxHandles) {
        curl_close($resource);
    } else {
        // Remove all callback functions as they can hold onto references
        // and are not cleaned up by curl_reset. Using curl_setopt_array
        // does not work for some reason,so removing each one
        // individually.
        curl_setopt($resource,null);
        curl_setopt($resource,null);
        curl_reset($resource);
        $this->handles[] = $resource;
    }*/
    curl_close($resource);
}

我希望它能对您有所帮助。

本文链接:https://www.f2er.com/2408416.html

大家都在问