Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 旋涡与外接力器_Php_Curl_Tor - Fatal编程技术网

Php 旋涡与外接力器

Php 旋涡与外接力器,php,curl,tor,Php,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,

我正在创建一个工具,我希望使用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
$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\u exec($this->ch);
$httpcode=curl\u getinfo($this->ch,CURLINFO\u HTTP\u代码);
如果($httpcode>=200&$httpcode<300){
返回$result;
}
返回$httpcode;//始终返回0
我不知道问题出在哪里。我的卷曲设置不正确吗

每个外部中继都不适合我,但我的本地中继可以工作


OS:OSX,但也在Windows上进行了测试

PHP:5.3.5


cURL:7.21.3

Tor通常非常慢,需要一秒以上的时间才能得到响应,因此首先尝试将CURLOPT_TIMEOUT更改为30左右,看看是否有帮助,如果没有,我们将进一步挖掘:)

另外,请将CURLOPT_CONNECTTIMEOUT设置为0(无限期)