我正在创建一个工具,我希望使用 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