Jump to content

Whois Script -- Fgets not returning anything.


jscix

Recommended Posts

The issue seems to be in the fgets loop, It hangs up for a decent time (i'd say 30-40 seconds), then sucessfully ends but the variable will contain no data.

 

I've tried the same loop, on an FTP port on my server and it sucessfully retreives data.. so i'm not positive what the problem is... Anyone see the problem or have some suggestions??

 

 


$wserver = "rs.internic.net";
$domainn = "testwhatever.com";

$cwhois  = @fsockopen("udp://" . $wserver, 43, $errn, $errstr, 30) or die("$errn - $errstr");
print "connected<br>";

fputs($cwhois, $domainn . "\r\n") or die("error sending request");
print "sent request<br>";

while (!feof($cwhois)) {
    $result .= fgets($cwhois, 200);
}
fclose($cwhois);
print "closed connection<br>";


if (eregi("No match for", $result)) {
    print "available";
} else {
    print "taken";
}

Maybe try using fread() instead of fgets(), since fgets() only gets 1 line at a time while fread() gets the total number of bytes regardless of line breaks.. Might want to read more than 200 bytes also, such as fread($cwhois, 4096)..

 

The only other thing I can think of is to try setting the socket timeout using stream_set_timeout($cwhois, 5) .. Your fsockopen() already specifies a 30 second timeout for connecting, but maybe the stream timeout would help too..

 

Good luck with it!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.