|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33816 gethostbyname() and fsockopen() inconsistant
Submitted: 2005-07-22 11:30 UTC Modified: 2005-07-22 20:21 UTC
From: sey at prometheus-designs dot net Assigned:
Status: Not a bug Package: Network related
PHP Version: 5.0.4 OS: Linux 2.4.29
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sey at prometheus-designs dot net
New email:
PHP Version: OS:


 [2005-07-22 11:30 UTC] sey at prometheus-designs dot net
I seem to be having inconsistant results using gethostbyname() and fsockopen().  On one hand I can make all the gethostbyname and fsockopen calls I want, as observed in:
( Source: )

However, in:
( Source: )

When one enters a domain in the first text box and nothing in the second, for example,, my script successfully gets the ip address of, but not  However, if is put in the second text box, forcing it to query first, it runs just fine.

What I believe to be the problematic code is in the get_raw_whois function I made.  Header.php and footer.php are only html with the exception of the date function used in header.php.  Phpinfo is:

Reproduce code:
function get_raw_whois( $whois, $domain )
	$ip = gethostbyname( $whois );
	print( 'Attempting to use ' . $whois . ' ( ' . $ip . ' ) ..<br />' );
	$fp = fsockopen( $whois, 43, $errno, $errstr, 30 );
	if( !$fp )
		$output = 'Could not perform whois: ' . $errno . ' ( ' . $errstr . ' )';
		fputs( $fp, $domain . "\r\n" );
		while( !feof( $fp ) )
			$temp = trim( fgets( $fp, 1024 ), "\x00..\x1F" );
			if( stristr( $temp, 'whois server:' ) )
				fclose( $fp );
				return get_raw_whois( substr( $temp, strpos( $temp, ':' ) + 1 ), $domain );
			$output .= $temp . '<br />';
	fclose( $fp );
	return $output;

Expected result:
$whois is supposed to be a uri to a whois server, $domain a domain name and tld.  First some text is printed about what whois server is being used.  Then a connection is made to that server, if it cannot be contacted in 30 minutes, failure.  Upon successful connection, the whois request is made.  The while statement ensures that all incoming data from the whois request is accounted for in some manner, barring exceptions.  Input is trimmed and then examined to contain 'whois server:'.  If this is found, it grabs that whois server off the end of that line, closes the connection, and recursively runs get_raw_whois, if not, it saves the input in to an output container.  After the whois server is done sending it's stuff, the connection is closed and output is returned to be printed on the screen.

Actual result:
After the recursive call is made, gethostbyname and fsockopen do not function properly.

Attempting to use ( ) ..
Attempting to use ( ) ..

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/.camella/sey/ on line 297

Warning: fsockopen() [function.fsockopen]: unable to connect to (Unknown error) in /home/.camella/sey/ on line 297

Warning: fclose(): supplied argument is not a valid stream resource in /home/.camella/sey/ on line 325
Could not perform whois: -1073765632 ( )


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-22 12:02 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

 [2005-07-22 19:13 UTC] sey at sey dot prometheus-designs dot net
The script is online, at .. The code segment I put in the 'reproduce code' box was just the function that I thought was messing up, as the rest of the script just formats user input and holds whois server information.  If you need, I can provide another link with a bit shorter version. using just the get_raw_whois function.
 [2005-07-22 19:41 UTC]
Please provide a *SHORT* but complete script the clearly shows the problem. "Short" means max. 10-20 lines long. We don't need all those arrays and functions. Just a reproduce script (comments and descriptions are welcome).
 [2005-07-22 20:06 UTC] sey at sey dot prometheus-designs dot net
I'm sorry but all I can get it down to without significantly altering it is 26 lines.  It can be found here:
( Source: )
 [2005-07-22 20:21 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Please debug your scripts yourself.
trim($whois) helps to remove spaces from the beginning of hostname.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Aug 09 23:03:35 2022 UTC