重写fsockopen以卷曲

时间:2014-02-28 13:04:35

标签: php curl

我有一个返回服务器响应的代码,但它使用的是fscokopen函数,这个函数在我正在使用的服务器上不可用。

如何将其重写为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( !@feof($fp) ){
                $data .= @fread($fp, 4096);
            }
            @fclose($fp);

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

1 个答案:

答案 0 :(得分: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