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.