jscix Posted May 17, 2007 Share Posted May 17, 2007 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"; } Quote Link to comment Share on other sites More sharing options...
phast1 Posted May 17, 2007 Share Posted May 17, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.