NameSilo

Fgets() taking over 1 min!

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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.
GoDaddyGoDaddy
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
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back