RE: [PHP] Issues w/ WHOIS and Fgets

From: Date: Tue, 07 Jan 2003 16:58:54 +0000
Subject: RE: [PHP] Issues w/ WHOIS and Fgets
Groups: php.general 
Request: Send a blank email to php-general+get-130614@lists.php.net to get a copy of this message
I was just about to reply that I found the problem, and you are correct. Fgets was reaching EOF, finding nothing, and tripping the die(). I was killing myself, quite literally. Thanks! -biv ------ Ben Vaughn Security Analyst Blackbird Technologies 703-796-1438 W / 703-868-5258 C bvaughn@blackbirdtech.com ------ -----Original Message----- From: Marek Kilimajer [mailto:kilimajer@webglobe.sk] Sent: Tuesday, January 07, 2003 11:57 AM To: Ben Vaughn Cc: php-general@lists.php.net Subject: Re: [PHP] Issues w/ WHOIS and Fgets 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 >------ > > >

Attachment: [text/x-vcard] Benjamin I Vaughn (Ben Vaughn).vcf
Attachment: [application/x-pkcs7-signature] smime.p7s
« previous php.general (#130614) next »