3

我正在创建一个工具,我希望使用 Tor 网络。

我熟悉 PHP 和它的 cURL 扩展,但我似乎无法使用 Tor 作为代理。我一直没有得到服务器的响应。

$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

我对问题可能是什么一无所知。我的 cURL 设置不正确吗?

每个外部中继都不适合我,但我的本地中继确实有效。


操作系统:OSX,但也在 Windows 上测试过

PHP:5.3.5

卷曲:7.21.3

4

1 回答 1

1

Tor 通常很慢,需要超过一秒才能得到响应,所以首先尝试将 CURLOPT_TIMEOUT 更改为 30 左右,看看是否有帮助,如果没有,我们会进一步挖掘 :)

PS 还将 CURLOPT_CONNECTTIMEOUT 设置为 0(无限期)

于 2011-12-14T09:29:31.337 回答