3

i am trying to fetch some external data on my PHP site, but having trouble with DNS resolving. When i use curl i get namelookup_time of about 8 seconds. Also tried file_get_contents with same lousy performance. Even gethostbyname takes about 8 seconds to resolve.

I am running php on apache web server, running on CentOS 6.6. My resolv.conf is using google DNS as nameserver, and I don't have any delay when i use dig, hosts, ping or any other DNS related Linux command. Also, if I do curl directly from Linux (or wget), I dont get any delay.

My question is are there any php or apache related dns configuration because i get slow DNS resolve only when using php code, and not when running any linux DNS related command.

UPDATE:

I have made small php script:

<?php
$start = microtime(true); 

gethostbyname("google.com");

$end = (microtime(true) - $start);
echo "elapsed time: $end";
?>

to get time of resolve, and when i run it on apache i get

elapsed time: 8.0323350429535

If i run using php from command line i get

elapsed time: 0.025190830230713

so it must be apache related issue.

joxwell
  • 41
  • 1
  • 10

0 Answers0