PHP Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 2: easy handle already used in multi handle

懵懂的女人 提交于 2021-02-07 17:03:54

问题


I am a user not a developer. The developer is not available.

This is the Google API library used in Google Shopping Products submission scripts.

The scripts worked successfully, every 20 minutes, for 2 years + the first 5 hours of yesterday.

Then the following error:

[18-Apr-2020 06:20:03 Europe/London] PHP Fatal error:  Uncaught GuzzleHttp\Exception\RequestException: cURL error 2: easy handle already used in multi handle (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in ../vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:162
Stack trace:
#0 ../vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(129): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 ../vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(89): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 ../vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(ThObject(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 ../vendor/guzzlehttp/guzzle/src/Handl in ../vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 162

The only server change at around the time the scripts stopped working was a security patch applied to the physical host and a server reboot.

PHP v7.3.16

I believe the Google library in use is v2.0

I can follow instructions although will probably not understand them!

TIA


回答1:


Just in case anyone reading this is using Laravel. We suddenly started having the same problem a few days ago, tried installing different cURL versions and setting cURL options, nothing worked. I fixed it by changing the vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php file. Look for the line that says

if (count($this->handles) >= $this->maxHandles) {
curl_close($resource);
} else {
...
}

Comment this all out, and instead of the if/else just write

curl_close($resource);

In other words no matter what the handles count is you always close the cURL connection. This worked instantly for us!

Hope it helps :)




回答2:


We solved this problem together with Stripe engineers yesterday (that's not to say your problem is Stripe-related, it isn't, but the problem/solution should be the same)

(These findings are not 100% confirmed, but appear to be the pattern): It's caused when making 2+ requests via cURL and appears to happen since one of the most recent versions of cURL or at least some other software (which may have updated automatically or been done by your hosting provider)

The solution we were provided is to disable persistent connections in cURL. There are different ways of how you could do that, depending on your implementation. But for inspiration, this is how we did it with Stripe:

$curl = new \Stripe\HttpClient\CurlClient();
$curl->setEnablePersistentConnections(false);
\Stripe\ApiRequestor::setHttpClient($curl);

I imagine it would be something similar to this for your libraries. And for those looking to solve this for Stripe, here it is :)

Notice: This solution will theoretically have an impact on latency, we have however not experienced this in practice yet. But now it's mentioned :)




回答3:


I have reverted to curl 7.69.1 and all is well again. For now, I have removed curl + libcurl from yum so they will not update. Thanks for your help and advice and apologies if my style has been incorrect.




回答4:


public_html/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php

please comment these lines from this fn

public static function wrapSync( callable $default, callable $sync ) {

    // return function (RequestInterface $request, array $options) use ($default, $sync) {
    //     return empty($options[RequestOptions::SYNCHRONOUS])
    //         ? $default($request, $options)
    //         : $sync($request, $options);
    // };

}




回答5:


I am not using guzzle, but I had same problem with other library

php 7.4.6

curl 7.19.7

CentOS release 6.10 (Final)

package "mercadopago/dx-php": "2.0.0"

On my dev server and other server i tested it works fine

I am not 100% but I think that is a bug on curl library that doesn't allow to reuse same curl connection for more than one request (again I am not sure about it).

I solved it with a hotfix on mercadopago/dx-php I edited ./vendor/mercadopago/dx-php/src/MercadoPago/RestClient.php

replacing line 150

from $connect = $this->getHttpRequest();

to $connect = new Http\CurlRequest();

in other words, force to use new connection for next request. on your code look where connection is reused and try to create new connection instead.

I know, it sucks because: - is a hotfix on Third-party - cannot reuse same connection

but it worked. Hope it can help you.



来源:https://stackoverflow.com/questions/61285075/php-fatal-error-uncaught-guzzlehttp-exception-requestexception-curl-error-2-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!