2014-02-28 63 views
0

我有一個返回服務器響應的代碼,但它使用的是fscokopen函數,該函數在我用於此項目的服務器上不可用。將fsockopen重寫爲捲曲

如何將其重寫爲CURL或類似的替代?

$server = 'whois.afilias.net'; 
$fp = @fsockopen($server, 43,$errno, $errstr, $this->m_connectiontimeout); 
     if($fp){ 
      @fputs($fp, $domain."\r\n"); 
      @socket_set_timeout($fp, $this->m_sockettimeout); 
      while([email protected]($fp)){ 
       $data .= @fread($fp, 4096); 
      } 
      @fclose($fp); 

      return $data; 
     }else{ 
      return "\nError - could not open a connection to $server\n\n"; 
     } 

回答

0
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
$result = curl_exec($ch); 
curl_close($ch); 

more options of curl