V
V
Vladimir2019-01-24 18:58:35
PHP
Vladimir, 2019-01-24 18:58:35

Why does curl request through different proxy servers give an error (5): Couldn't resolve proxy name?

I'm trying to parse the site, it's not possible to pass through my curl server anymore, so I substitute an array of proxy servers in curl, at first the download goes fine and then it gives
cURL error (5): Couldn't resolve proxy name
Warning: curl_errno(): supplied resource is not a valid cURL handle resource in /var/www/docs/site/curltest.php on line 30

function getCurlResult ($url) {
  global $arrProxy;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLPROTO_HTTPS,1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
  curl_setopt($ch, CURLOPT_PROXY, $arrProxy[0]);
  // curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);// таймаут в секундах
  $htmltext = curl_exec($ch);
  curl_close($ch);

  while (strlen($htmltext) < 100) {
    echo "<h3>delete PROXY API!!!! " . $arrProxy[0] . " осталось "  . (count($arrProxy) - 1) . "</h3>";
    $arrProxy = array_slice($arrProxy, 1);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLPROTO_HTTPS,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
    curl_setopt($ch, CURLOPT_PROXY, $arrProxy[0]);
    // curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    $htmltext = curl_exec($ch);
    if($errno = curl_errno($ch)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    }
    curl_close($ch);
    if (count($arrProxy) < 1) {
      echo "<h1>PROXY API адресса закончились!!!</h1>";
      exit;
    }		
  }
  
  //$htmltext = iconv("CP1251", "UTF-8", $htmltext);
  return $htmltext;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir L, 2019-01-28
L

Found the problem by changing the line
curl_setopt($ch, CURLOPT_PROXY, $arrProxy[0]);
to
curl_setopt($ch, CURLOPT_PROXY, trim($arrProxy[0]));

D
Dimonchik, 2019-01-24
@dimonchik2013

run out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question