Hello, Long time reader, first time e-mailer :-). I am having a pretty strange issue with fgets and a socket, and was hoping that perhaps someone here can help me. First, my code:
function dowhois($who) { $data = array(""); $whom = trim($who); $fp = fsockopen ("127.0.0.1", 43, $errno, $errstr, 30) or die("Could not open socket to proxy"); if (!$fp) { die("$errstr ($errno)\n"); } else { fputs ($fp, "$whom\r\n") or die("Could not write to socket"); while ($fp && !feof($fp)) { $packet = fgets($fp, 4096) or die("Could not read from socket"); array_push($data, $packet) or die("Could not push data into array"); } fclose ($fp); } return $data; } As you can see, this is a function that accepts a string as an argument and is supposed to open a connection to a local WHOIS server, query for that string and return the results in an array. Unfortunately, when I call this function I always trip the third die();, "Could not read from socket." fgets always trips this. I am running PHP 4.3.0. I will also share some things I have learned in the last two days worth of problem-solving: - If I use fread instead of fget, I can pull the data, although it looks pretty worthless (I need \n terminated to parse the output properly) - Changing $fp from blocking to non-blocking alleviates no problems - Changing the max line length to anything does not cause issues - I have turned on auto_detect_line_endings to no avail - I have a pretty much identical script that does an HTTP query and that works. 3rd party php scripts that use sockets also work. It seems that WHOIS is causing the problem? Thanks for any help anyone can provide! Regards, Ben ------ Ben Vaughn Security Analyst Blackbird Technologies 703-796-1438 W / 703-868-5258 C [EMAIL PROTECTED] ------
BEGIN:VCARD VERSION:2.1 N:Vaughn;Ben FN:Ben Vaughn TEL;WORK;VOICE:703.796.1438 TEL;HOME;VOICE:703.205.9719 TEL;CELL;VOICE:703.868.5258 ADR;WORK:;217-C LABEL;WORK:217-C EMAIL;PREF;INTERNET:[EMAIL PROTECTED] REV:20020607T194757Z END:VCARD
smime.p7s
Description: application/pkcs7-signature