Dynadot โ€” .com Registration $8.99

Fgets() taking over 1 min!

Spaceship Spaceship
Watch

Barrucadu

Established Member
Impact
64
This code takes over 1 minute to execute, any idea why?

PHP:
<?php

$socket = fsockopen($_GET['server'], 43);
fwrite($socket, $_GET['domain']);

$found_anything = 'no';
$whois = '';

while(!feof($socket) && $found_anything != 'yes'){
	$line = fgets($socket,1024);
	if(eregi('No Match',$line) || eregi('Not Found',$line) || eregi('No Such Domain',$line)){
		$found_anything = 'yes';
	}
	$whois .= $line;
}

fclose($socket);

if(eregi('No Match',$whois) || eregi('Not Found',$whois) || eregi('No Such Domain',$whois)){
	echo 'Free';
}else{
	echo 'Taken';
}

?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
try using fputs instead of fwrite
 
0
•••
Nope, still takes ages
 
0
•••
just to double check have you connected yourself to see if it takes ages to connect? And have you checked any error logs to ensure something isnt going wrong when connecting?
 
0
•••
Try:
PHP:
<?php

$socket = fsockopen($_GET['server'], 43);
fwrite($socket, $_GET['domain'] . "\r\n");

$found_anything = false;
$whois = '';

while (!feof($socket) AND !$found_anything)
{
    $line = fread($socket, 128);

    if (preg_match('#(No Match|Not Found|No Such Domain)#', $line))
    {
        $found_anything = true;
    }
    $whois .= $line;
}

fclose($socket);

echo (preg_match('#(No Match|Not Found|No Such Domain)#', $whois)) ? 'Free' : 'Taken';

?>
I tried yours, and it does take a while - the above works fine though.
 
1
•••
works perfectly SV, rep added
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back