linux - Set timeout to a PHP function -
i have script
<?php function get_reverse_dns($ip) { $result = exec("nslookup -n ".escapeshellarg($ip)." | grep 'name = '"); if(strpos($result,"name =") === false) { return "no reverse"; } else { $result = trim($result); $explodedresult = explode("name =",$result); $explodedresult[1] = trim($explodedresult[1]); $reversedns = trim($explodedresult[1],"."); return $reversedns; } } ?>
that gives me reverse dns, problem sometimes, ip can have long delay, , want script check ip can "looked up", , if 5 seconds passed , not happening, return false
how can make that?
i have tried in linux
nslookup --timeout 5 1.1.1.1 | grep 'name = ' timeout 5 nslookup 1.1.1.1 | grep 'name = '
thanks.
i use dig: dig -x ${ip} +time=5 +tries=1 +retry=0 +short
this command return ip address simplify parsing bit.
Comments
Post a Comment