Fgets() taking over 1 min!

SpaceshipSpaceship
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
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
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back