0

we're seeing a very odd issue with PHP taking a very long to resolve any hostname, which happens randomly every 5-10 attempts. We have used the following script to check it out...

<?php

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;

$host = "google.com";
echo "looking up ".$host."<br/>";
$ip = gethostbyname($host)
//$ip = rtrim(`/usr/bin/dig $host A +short | /usr/bin/tail -1`);
echo "IP = " . $ip . "<br/>";

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "<br/>Total Time: ".$totaltime." seconds";

?>

To look up google.com is mostly taking milliseconds, but one in 5-10 attempts it will take 10-15 seconds! We see the same behaviour for any domain name. The commented out line uses dig from the command line to resolve, when this is used instead we see no issue. This is all very weird as they are using the same resolver. We have run this PHP script from the command line to take apache out of the equation too - same result, so it seems to be purely a PHP issue.

The PHP docs say the gethostbyname() function can take up to 4 seconds - we're seeing considerably longer than this. We don't actually use this function - the real problem we have is with cURL calls timing out due to not being able to resolve the hostname. The script above is purely to assess whether we have a resolving problem in PHP, which we do!

At a total loss atm - googling has turned up very little. Even pointers to where we might start the investigation would be greatly appreciated.

Thanks.

1 Answers1

0

I would start with looking at where your DNS is resolving, where is the DNS currently pointed on your server? Maybe try changing it to one of the public DNS servers (8.8.8.8 or 4.2.2.2) and see if you experience the same issues.

OrganizedChaos
  • 431
  • 2
  • 11
  • What kind of server is this on? Is this a shared host, VPS, physical host? Can you watch the resources on the server and see if there is something hogging resources every so often that would cause delays on what should be normal actions? I have seen similar issues when storage was over utilized and the I/O's couldn't keep up with the server requests. Also, if you get a constant ping going from the command line, do you get the delays there ever so often? – OrganizedChaos Feb 13 '13 at 04:16