cURL 和外部 Tor 中继

发布于 2024-12-07 06:42:10 字数 1048 浏览 3 评论 0原文

我正在创建一个工具,并且希望使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷→糖丶微凉 2024-12-14 06:42:10

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文