phpfsockopen

ERROR: 0 - php_network_getaddresses: getaddrinfo failed: Name or service not known


i have one problem.. i use this function

public function check_ch($prt){

        $ip = "xx.xx.xx.xxx";
        $port = $prt;

       $fp = @fsockopen($site, $port, $errno, $errstr);
            if (!$fp)
              // return $port;
                return "ERROR: $errno - $errstr<br />\n";
            else
                return 1;

    }

and i got this error..

ERROR: 0 - php_network_getaddresses: getaddrinfo failed: Name or service not known

But only in php .. i have some function in python but there it works . see here:

SERVER1_CHANNEL_DICT = {
    1:{'key':11,'name':'Canal 1','ip':'xx.xx.xx.xxx','tcp_port':13431,'udp_port':13431,'state':STATE_NONE,},
    2:{'key':12,'name':'Canal 2','ip':'xx.xx.xx.xxx','tcp_port':13461,'udp_port':13461,'state':STATE_NONE,},
    3:{'key':13,'name':'Canal 3','ip':'xx.xx.xx.xxx','tcp_port':13491,'udp_port':13491,'state':STATE_NONE,},
    4:{'key':14,'name':'Canal 4','ip':'xx.xx.xx.xxx','tcp_port':13521,'udp_port':13521,'state':STATE_NONE,},
    5:{'key':15,'name':'Canal 5','ip':'xx.xx.xx.xxx','tcp_port':13551,'udp_port':13551,'state':STATE_NONE,},
    6:{'key':16,'name':'Canal 6','ip':'xx.xx.xx.xxx','tcp_port':13581,'udp_port':13581,'state':STATE_NONE,},
}

check the pictures enter image description here

and i don't know why in php doesn't work.. help me please.. when i call the function i put the port .. $this->check_ch(13431) ..


Solution

  • Logical to me: the fsockopen() first argument $site is not set. I presume it should be $ip instead of $site. By the way you should be careful as fsockopen() returns a ressource, when checking for it's return you should strict test.

    public function check_ch($prt)
    {
        $ip = "xx.xx.xx.xxx";
    
        $fp = @fsockopen($ip, $prt, $errno, $errstr);
        if ($fp === false) {
            // return $port;
            return "ERROR: $errno - $errstr<br />\n";
        } else {
            return 1;
        }
    }
    

    EDIT: When you silence a function with a @, if you get a problem, the first reflex to have is to unsilence it. You should have a report that $site is not set if it was unsilenced ;)