2015-06-25 28 views
1

如果我有2个代理:PHP卷曲要求使用代理不同协议

$proxy1 = array('http', 'XXX.XXX.XXX.XXX','8080')$proxy2 = array('https','YYY.YYY.YYY.YYY','80')

而且我请求: $url1="http://somesite-1.net"$url2="https://somesite-2.net"

代码以初始化多卷曲:

foreach ($urls as $url) { 
      // threads 
      $ch = curl_init($url); 
      curl_setopt($ch, CURLOPT_AUTOREFERER, $_autoreferrer); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $_follow_loc); 
      curl_setopt($ch, CURLOPT_MAXREDIRS, $_max_redirects); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
      curl_setopt($ch, CURLOPT_HEADER, 0);     

      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $_connection_timeout);     curl_setopt($ch, CURLOPT_TIMEOUT, $_curl_timeout); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLINFO_HTTP_CODE,  true); 
      curl_setopt($ch, CURLOPT_PROXY,   $this->conf->getProxyIP().":".$this->conf->getProxyPort());  //PROXY  
      curl_setopt($ch, CURLOPT_USERAGENT,  $this->conf->getUserAgent());         
      if($referrer = $this->conf->getReferrer() !== false){             //REFERRER 
       curl_setopt($ch, CURLOPT_REFERER, $referrer); 
      } 



      $tasks[$url] = $ch; 

      curl_multi_add_handle($cmh, $ch); 
     } 

我是否需要设置代理协议http或https发送请求ST? 因为当我,使用套接字检查代理 - 我得到的消息,所有好的和代理工作。但是当我使用cURL请求内容时 - 我从所有代理获取内容。我认为问题是没有设置代理协议。我认为我需要在cURL中设置一些选项,但不知道具体是什么。

回答

0
/** 
* get curl_setopt() params 
* 
* @since 2015/03/21 Saturday 
* @return array 
*/ 
private function __optSets(){ 
    $this->__setCookie(); 
    // default:GET 
    $options = array(
      CURLOPT_HEADER => 0, 
      CURLOPT_RETURNTRANSFER => true, 
      CURLOPT_PORT => $this->port, 
      CURLOPT_REFERER => $this->reffer, 
      CURLOPT_USERAGENT => $this->userAgent, 
      CURLOPT_ENCODING =>'', 
      CURLOPT_COOKIE =>$this->_cookie, 
      CURLOPT_HTTPHEADER =>$this->_requestHeader, 
      CURLOPT_HTTPGET => true, 
      CURLOPT_POST => false, 
      CURLOPT_CONNECTTIMEOUT => $this->_connect_timeout 
    ); 
    // if:POST 
    if(self::HTTP_MEHTOD_POST === $this->method){ 
     $options[CURLOPT_HTTPGET] = false; 
     $options[CURLOPT_POST] = true; 
     $options[CURLOPT_POSTFIELDS] = $this->_poststr; ////default type:application/x-www-from-urlencoded 
    } 

    // if:HTTPS 
    if ($this->_isHTTPS) { 
     $options [CURLOPT_PORT] = 443; // !Very important 
     $options [CURLOPT_SSL_VERIFYPEER] = false; 
     $options [CURLOPT_SSL_VERIFYHOST] = false; 
    } 

    // if:enableProxy 
    if(true === $this->enableProxy){ 
     $options [CURLOPT_PROXY] = $this->_proxyIP; 
     $options [CURLOPT_PROXYPORT] = $this->_proxyPort; 
    } 

    return $options; 
} 
+0

这是我的课,可以引荐这样的:https://github.com/phpjungle/iHttp/ – PHPJungle

+0

见法__optSets(),行:282 – PHPJungle

+0

哦,谢谢。我会检查它。附:漂亮的个人资料图 – LINKeRxUA