CURL connect to proxy server

Hi Guys!

I’m trying to connect to a proxy server using PHP CURL method. The proxy IP is a I get a blank page when I try using the following script, am I doing something wrong?

$url = "";
$ch = curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		curl_setopt($ch, CURLOPT_COOKIE, $cookies);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "field1=value1&field2=value2");
		curl_setopt($ch, CURLOPT_REFERER, '');
		curl_setopt($ch, CURLOPT_PROXY, "");
		curl_setopt($ch, CURLOPT_HTTPHEADER,
			"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3",
			"Accept-Language: en-US,en;q=0.8",
			"Cache-Control: max-age=0",
			"Connection: keep-alive",
			"Content-Type: application/x-www-form-urlencoded",
			"Cookie: ".implode(" ",$new_cookies)));
		$response = curl_exec($ch);
		print_r($response); exit;

The first thing to do is add some error checking so you can report any errors cURL may report. After doing that and testing your script, I saw it was timing out. Since proxies can be slow, I increased the timeout with no luck. So I checked the proxylist on the site you specified and I didn’t see that proxy IP listed… so it seems you may have a bad proxy.

You also didn’t specify the port for the IP. Many, if not most proxies use ports other than 80. You also have to pay attention to whether it’s an HTTP proxy or a SOCKS proxy. If it’s HTTP, you don’t have to worry about setting the cURL option as HTTP is the default.

I also removed some of the unneeded options.

Here is my working (as of this post) example:


$url = "";

// Testing proxy speed
$loadtime = time();

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_PROXY, ""); // Don't forget the port of the proxy... they're not all 80

$response = curl_exec($ch);

// Testing proxy speed
echo "cURL time: " . (time() - $loadtime) . "s<br />\

if ($response === false) {
    echo "cURL Error: ", curl_error($ch);
} else {
    echo $response;