A
A
Andrey Angelovich Stock2018-05-11 14:51:55
PHP
Andrey Angelovich Stock, 2018-05-11 14:51:55

How to fix cURL error(7)?

Hi all! there is a code that interacts with the Yandex API

$method3 = 'GetWordstatReportList';

$request3 = array(
    'token' => $token,
    'method' => $method3,

);
$request3 = json_encode($request3);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $serv_addr); // set url to post to
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_HTTPHEADER, $post_headers); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $request3); // add POST fields
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$response = curl_exec($ch); //получил ответ от сервера
if($errno = curl_errno($ch)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
}
curl_close($ch);


if ($response === false) {
    die("Произошел сбой. Попробуйте еще раз");
    print_r($response);
    echo $response;

}
$result3 = json_decode($response, true);
if (!isset($result3))
    die("JSON decode error. " . $response);
if (!isset($result3['data']))
    die("Element 'data' not found. " . $response);

And now from time to time (not always!) I get in response cURL error (7): Couldn't connect to server
What could it be and how to get rid of it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question