Help, who knows, here is the function:

function curl_exec_follow($url) { $agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1'; // Some websites check referrer $host = parse_url($url, PHP_URL_HOST); $scheme = parse_url($url, PHP_URL_SCHEME); $referrer = $scheme . '://' . $host; $ch = curl_init(); $curl_defaults = array( CURLOPT_HEADER => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, ); curl_setopt_array($ch, $curl_defaults); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_REFERER, $referrer); curl_setopt($curl, CURLOPT_PROXYTYPE,CURLPROXY_HTTP); curl_setopt($ch,CURLOPT_TIMEOUT,30); curl_setopt($ch, CURLOPT_PROXY,"xxx:xxx"); curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL,0); curl_setopt($ch, CURLOPT_PROXYUSERPWD,"xxx:xxx"); curl_setopt($ch, CURLOPT_PROXYAUTH,CURLAUTH_ANY); curl_setopt($ch, CURLOPT_FRESH_CONNECT,true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); if ( !file_exists('cookie.txt') || !is_writable('cookie.txt') ) { echo 'Cookie file is missing or not writable.'; exit; } curl_setopt($ch, CURLOPT_COOKIESESSION, 0); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch,CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch,CURLOPT_LOW_SPEED_LIMIT, 1); curl_setopt($ch,CURLOPT_LOW_SPEED_TIME, 10); $content = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ( $code != '200' ) echo 'http error code: ' . $code . ' error:' . .curl_error($ch); curl_close($ch); return $content; } 

When I call it without a proxy, everything works. When I tried to work with free proxies without authorization, it was rare, but sometimes it worked. I decided that the problem is that they are free and bought a paid proxy with authorization. When calling the function curl_error($ch) returns the error Failed to connect to xxxx port xxxx: Connection refused

Who knows, help please) I have already run out of options (

  • And what is the proxy type? Means at purchased. - Alexey Shatrov
  • Proxy type http / https - Dmitry Dybin

1 answer 1

So guys, I figured it out. The code is all right. It turns out hosting providers generally prohibit requests with non-standard ports. And the proxy servers are just non-standard. I asked them to allow me to send requests to my port and it all worked)