Heim >Backend-Entwicklung >PHP-Tutorial >linux - php使用Curl调用接口 速度非常慢, 把 域名换成Ip速度就正常啦.

linux - php使用Curl调用接口 速度非常慢, 把 域名换成Ip速度就正常啦.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:09:181773Durchsuche

function requestCurl($url,$type = 'get',$data=NULL)

<code>{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    if('post'==$type){
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }else if('delete'==$type){
        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");   
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    }else if('put'==$type){
        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");   
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    }
    curl_setopt($ch, CURLOPT_URL,$url);
    $infos = curl_exec($ch);
    curl_close($ch);
    return $infos;
}</code>

在主机ping也可以. 大神求指导 不胜感激

回复内容:

function requestCurl($url,$type = 'get',$data=NULL)

<code>{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    if('post'==$type){
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }else if('delete'==$type){
        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");   
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    }else if('put'==$type){
        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");   
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    }
    curl_setopt($ch, CURLOPT_URL,$url);
    $infos = curl_exec($ch);
    curl_close($ch);
    return $infos;
}</code>

在主机ping也可以. 大神求指导 不胜感激

dns域名解析问题而已。其实我也不太懂。你最好做个配置 把相应域名转换为ip

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn