From:             sey at prometheus-designs dot net
Operating system: Linux 2.4.29
PHP version:      5.0.4
PHP Bug Type:     Network related
Bug description:  gethostbyname() and fsockopen() inconsistant

Description:
------------
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:

http://sey.prometheus-designs.net/meh/index2.php
( Source: http://sey.prometheus-designs.net/meh/index2.phps )

However, in:

http://sey.prometheus-designs.net/meh/index.php
( Source: http://sey.prometheus-designs.net/meh/index.phps )

When one enters a domain in the first text box and nothing in the second,
for example, apple.com, my script successfully gets the ip address of
whois.verisign-grs.net, but not whois.markmonitor.com.  However, if
whois.markmonitor.com is put in the second text box, forcing it to query
whois.markmonitor.com 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:

http://sey.prometheus-designs.net/phpinfo.php

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 . '
)';
        }
        else 
        {
                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 whois.verisign-grs.net ( 198.41.3.54 ) ..
Attempting to use whois.markmonitor.com ( whois.markmonitor.com ) ..

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses:
getaddrinfo failed: Name or service not known in
/home/.camella/sey/sey.prometheus-designs.net/meh/index.php on line 297

Warning: fsockopen() [function.fsockopen]: unable to connect to
whois.markmonitor.com:43 (Unknown error) in
/home/.camella/sey/sey.prometheus-designs.net/meh/index.php on line 297

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

-- 
Edit bug report at http://bugs.php.net/?id=33816&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33816&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33816&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33816&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33816&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33816&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33816&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33816&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33816&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33816&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33816&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33816&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33816&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33816&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33816&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33816&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33816&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33816&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33816&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33816&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33816&r=mysqlcfg

Reply via email to