Google MyBusiness PHP Api OpenSSL SSL_connect: SSL_ERROR_SYSCALL

#laravel #google-api #openssl #google-api-client #php-curl

Вопрос:

Часть моего кода такова:

 try {

    $client = new Google_Client();
    $client->setAuthConfig($credentials_file);

    $client->setAccessType("offline");
    $client->setIncludeGrantedScopes(true);
    $client->addScope("https://www.googleapis.com/auth/plus.business.manage");
}catch(GuzzleHttpExceptionConnectException $e){
    Connector::handleException($e); //just print $e->getMessage(); and die();
}catch(Exception $e){
    Connector::handleException($e); //just print $e->getMessage(); and die();
}

if (isset($_SESSION['access_token']) amp;amp; $_SESSION['access_token']) {

    $client->setAccessToken($_SESSION['access_token']);
    $connector = Connector::init($client);

    require_once "views/index.php";

} else {
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
 

в views/index.php я просто получаю местоположения и распечатываю их.

я запускаю свое «приложение» с помощью php -S localhost:8000

Почти все в порядке, потому что время от времени у меня возникают ошибки:

cURL error 35: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to mybusiness.googleapis.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

и

cURL error 35: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to oauth2.googleapis.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Мне нужно пару раз обновить сайт, пока все не придет в норму. Несколько дней назад все было хорошо. Иногда он начинает работать после первого обновления, иногда это занимает 5 минут.

Почему? Могу ли я как-то это исправить?

Ответ №1:

Похоже, что у Google API есть проблемы с curl с IPv6, поэтому в файле:

vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php

о строке 40 я добавил:

curl_setopt($easy->handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

и это решило проблему!