I have the following code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
if ($use_proxy) {
$proxies = [
'(proxy-IP):3128'
];
$proxy_key = array_rand($proxies);
$proxy = $proxies[$proxy_key];
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
$html = curl_exec($ch);
But when I run it and try to use curl through a proxy, I get the following error: Failed to connect to (proxy-ip) port 3128 after 1003 ms: Connection refused.
However, the port is fine, and the IP is fine. Obviously there's something missing, but I have been experimenting with variations of the code, and I still cannot connect to the proxy.