Tim S.
Tim S.

Reputation: 13853

cURL and an extern Tor relay

I'm creating a tool and I wish to use the Tor network.

I am familiar with with both PHP and it's cURL extension but I just cant seem to use Tor as proxy. I keep getting no response from the server.

$this->ch = curl_init();

curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($this->ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($this->ch, CURLOPT_NOSIGNAL, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 1);

curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_USERAGENT, $this->useragents[array_rand($this->useragents, 1)]);

$result = curl_exec($this->ch);
$httpcode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

if($httpcode >= 200 && $httpcode < 300) {
    return $result;
}

return $httpcode; // Always returns 0

I'm rather clueless what the problem could be. Are my cURL settings incorrect?

Every extern relay doesn't work for me, but my local relay does work.


OS: OSX, but tested on Windows as well

PHP: 5.3.5

cURL: 7.21.3

Upvotes: 3

Views: 1072

Answers (1)

mangefort
mangefort

Reputation: 353

Tor is usually really slow and needs much more than one sec to get the response, so first try changing CURLOPT_TIMEOUT to something like 30 or so and see if it helps, if not we'll dig further :)

P.S. Also set CURLOPT_CONNECTTIMEOUT to 0 (indefinitely)

Upvotes: 1

Related Questions