0

I connect to the whois server and am able to retrieve the availability of a domain name. Somehow I am not able to get a response back using the same connection when I do a request of a different domain name.

<?php
$context = stream_context_create();
if($fp = stream_socket_client("tcp://whois.eu:43", $errno, $errstr, 30, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $context)) {

    stream_set_timeout($fp, 30);
    
    $domains = array('test.eu','amaai.eu');
    foreach($domains as $domain) {  
        fwrite($fp, $domain."\r\n");
        $contents = '';
        while (!feof($fp)) {
            $contents .= fread($fp, 8192);
        }

        echo $domain.": ".$contents;
    }

    fclose($fp);
}

What am I missing? I really want to use the same connection.

sjors
  • 13
  • 4

1 Answers1

1

The WHOIS protocol only supports one query. The server closes the connection after sending a response. You need to reconnect for each query.

rveerd
  • 3,620
  • 1
  • 14
  • 30
  • As explained and defined in RFC 3912 "WHOIS Protocol Specifications" §3 "Protocol Example" and §2: "The WHOIS server closes its connection as soon as the output is finished." – Patrick Mevzek Jun 29 '20 at 04:51