Jump to content

Getting Host Name taking too long


gnznroses

Recommended Posts

I'm looking up the host name of IPs, and it's taking waaay too long on some IPs.

I read on php.net that gethostbyaddr can sometimes do this -- and it was -- so I switched to some other code that was posed in the comments there, but it's doing the same thing.

 

This is supposed to impose a limit of two seconds on the lookup. I added some code to time it however, and it's not.

  $t1 = microtime(true);
  //$hostname = gethostbyaddr($ip);
  // max two secs
  $output = `host -W 2 $ip`;
  if (ereg('.*pointer ([A-Za-z0-9.-]+)\..*',$output,$regs)) {
    $hostname = $regs[1]; 
  }else{
    $hostname = $ip;
  }
  $t2 = microtime(true);
  if (($t2 - $t1) > 2){
    $t2 = round($t2,3);
    // insert warning into database
  }

 

I'm still getting warnings that it's taking 1235072093.3 seconds on some IPs.

 

any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/146023-getting-host-name-taking-too-long/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.