1

I have a job that runs once in a week and retrieves a bunch of 700 hostnames. I need to translate those into IP adresses. My first experiment was calling the php native function "dns_get_record", storing the results into DB.

Due to the amount of dns queries to do, the script made my server freeze and, maybe the guys from DNS support thought it was getting attacked.

Now I'm thinking in spread this queries throughout 6 hours, maybe 12 after script startup. So I thought of making use of sleep(30) in the end of the foreach loop. Is it the best way to do this?

Do you have any other suggestion to make it lighter to my server and so to the DNS?

Thanks

gugabguerra
  • 635
  • 1
  • 5
  • 8
  • http://unix.stackexchange.com/questions/20784/how-can-i-resolve-a-hostname-to-an-ip-address-in-a-bash-script move this operation into a shell script or something – Alex Andrei Nov 26 '15 at 15:37
  • Thanks, but I'd like to continue using PHP. Even if shell script can do it with better performance, I need to reduce the amount of queries per second, to go easy and not affect my DNS. – gugabguerra Nov 26 '15 at 15:44

1 Answers1

1

save the last queried time to db and then query ur DNS list with using this list? of couse shell script will even be needed to run the php script like every 10 second etc. with that script u can check the last query time and if 30 seconds passed then remake your query etc...

Murat Cem YALIN
  • 317
  • 1
  • 6
  • Seems to be a good solution. Store the query time for each hostname into DB, then retrieve first hostname where last query field is higher than 7 days and try to resolve it, updating last query time. Is it your suggestion? – gugabguerra Nov 26 '15 at 16:12
  • yes something like that. you can make many different scenarios out of it. – Murat Cem YALIN Nov 26 '15 at 16:16
  • Implemented! Doing 2 DNS queries each 5 minutes via crontab. I got my entire database resolved in two hours. Soft! Thanks – gugabguerra Nov 27 '15 at 10:26