cURL 和外部 Tor 中继
我正在创建一个工具,并且希望使用 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
cURL:7.21.3
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tor 通常非常慢,需要超过一秒才能获得响应,因此首先尝试将 CURLOPT_TIMEOUT 更改为 30 左右,看看是否有帮助,如果没有,我们将进一步挖掘:)
PS 还将 CURLOPT_CONNECTTIMEOUT 设置为 0 (无限期)
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)