Re: Issues w/ WHOIS and Fgets

From: Date: Tue, 07 Jan 2003 16:57:26 +0000
Subject: Re: Issues w/ WHOIS and Fgets
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130613@lists.php.net to get a copy of this message
try if(($packet = fgets($fp, 4096)) === false) die(...); instead. The same for array_push Ben Vaughn wrote:
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 bvaughn@blackbirdtech.com ------


« previous php.general (#130613) next »