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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -