0

I am currently trying to connect to nominets whois service via fsockopen but I'm having a problem reading the reply.

code used:

$fp = fsockopen("whois.nic.uk", 43, $errno, $errstr);

if (!$fp) {
    echo "ERROR: $errno - $errstr<br />\n";
} else {
echo "<h1>Connected To The WHOIS Server.</h1>\n\n";
}


fwrite($fp, "madeupdomain.co.uk\r\n");
$lookup = fread($fp, 4096);
fclose($fp);


echo $lookup;

Now I succesfully connect to the WHOIS server and receive a reply but it always misses the end off.

Domain name: madeupdomain.co.uk Registrant: Made Up Inc. Registrant type: Unknown Registrant's address: 123 Fake Road City UK Registrar: Made Up. t/a Madeup[Tag = MADEUP] URL: http://www.madeupadomain.com Relevant dates: Registered on: 14-Feb-1955 Renewal date: 11-Feb-2016 Last updated: 11-Feb-2001 Registration status: Registered until renewal date. Name servers: ns1.madeupnamesrver.com ns2.madeupnamesrver.com ns3.madeupnamesrver.com ns4.madeupnamesrver.com WHOIS lookup made at 00:00:00 07-Dec-2011 -- This WHOIS information is provided for free by Nominet UK the central registry for .uk domain names. This information and the .uk WHOIS are: Copyright Nominet UK 1996 - 2011. You may not access the .uk WHOIS or use any data from it except as permitted by the terms of use available in full at http://www.nominet.org.uk/whois, which includes restrictions on: (A) use of the data for advertising, or its repackaging, recompilation, redistribut

As you can see it's missing the last part of a true whois lookup, this always happens but the position where it is cut off changes depending on what domain I query.

Does anyone have any suggestions?

Thanks.

Hairzo
  • 107
  • 1
  • 2
  • 10

1 Answers1

3

You only read 4096 bytes:

fread($fp, 4096);

If you want to read more than that (which you obviously need to) just increase the number or loop until EOF:

while (!feof($fp)) {
   $contents .= fread($fp, 8192);
}
halfdan
  • 33,545
  • 8
  • 78
  • 87
  • Thank you, this seems to have solved it using the loop untill end of file. fread($fp, 4096); Increasing the above to 8192 on it's own without the EOF didn't do anything...just curious as to why? Thanks – Hairzo Dec 07 '11 at 23:59
  • It takes time to send data, and the remote server isn't able to return the whole response before you start reading. –  Dec 08 '11 at 00:14
  • Illogical to put any sleep(), as that would make it take longer, and there's already a sleep with a blank null from fread whenever it takes time (though it never does honestly) unless you set stream_set_timeout(). – Raiden Sep 11 '12 at 01:59