尽管设置了参数CURLOPT_RETURNTRANSFER,但为什么curl返回1 [英] Why curl returns 1 although parametre CURLOPT_RETURNTRANSFER is set

查看:74
本文介绍了尽管设置了参数CURLOPT_RETURNTRANSFER,但为什么curl返回1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

this is the servers array that I keep top level domain names and extensions

 protected $servers = array(
        
        "com.tr" => "whois.nic.tr",
        "gen.tr" => "whois.nic.tr",
        "web.tr" => "whois.nic.tr",
        "k12.tr" => "whois.nic.tr",
        "org.tr" => "whois.nic.tr"
    );





我尝试过:





What I have tried:

I am required to get whois info so I wrote this function


    function whois($domain,$ext)
    {
               $server=$this->servers[$ext];
               $domain=$domain.".".$ext;
             
        if (function_exists('curl_version')) {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $server);
            curl_setopt($curl, CURLOPT_PORT, 43);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 5);
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $domain."\r\n");
            $result = curl_exec($curl);
            curl_close($curl);

                    
                    echo print_r($result);
                   
        } else {
            trigger_error('cURL is not found!');
            exit();
        }




    }

I  am using this way
whois("google","com");

This function works  for google.com and It gives me the correct domain information But when I execute  for google.org.tr then (this is the intersting part)  sometimes retuns 

    
    No match found for "google.org.tr"(whis is expected)
 
     and  somethimes return "1"

推荐答案

servers = array(

com.tr=>whois.nic.tr,
gen.tr=> whois.nic.tr,
web.tr=>whois.nic.tr,
k12.tr=>whois.nic.tr,
org.tr=>whois.nic.tr
);
servers = array( "com.tr" => "whois.nic.tr", "gen.tr" => "whois.nic.tr", "web.tr" => "whois.nic.tr", "k12.tr" => "whois.nic.tr", "org.tr" => "whois.nic.tr" );





我是什么尝试过:





What I have tried:

I am required to get whois info so I wrote this function


    function whois(


domain,


ext)
{
ext) {


这篇关于尽管设置了参数CURLOPT_RETURNTRANSFER,但为什么curl返回1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆