NameSilo

Fgets() taking over 1 min!

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
try using fputs instead of fwrite
 
0
Close
Nope, still takes ages
 
0
Close
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
Close
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
Close
works perfectly SV, rep added
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back