note 92870 added to function.gethostbyname

From: Date: Wed, 12 Aug 2009 15:52:04 +0000
Subject: note 92870 added to function.gethostbyname
Groups: php.notes 
Request: Send a blank email to php-notes+get-159372@lists.php.net to get a copy of this message
This is the best method I've come up with to resolve any host-name to ip-address, it's quick and reliable and has support for timeout! An invalid address, a unicode string for exmaple, returns after 4~ seconds, instead of 8~ with gethostbyname! It works only with unix though. <?php function getAddrByHost($host, $timeout = 3) { $query = nslookup -timeout=$timeout -retry=1 $host; if(preg_match('/\nAddress: (.*)\n/', $query, $matches)) return trim($matches[1]); return $host; } ?> ---- Server IP: 82.80.248.162 Probable Submitter: 79.177.63.202 ---- Manual Page -- http://www.php.net/manual/en/function.gethostbyname.php Edit -- https://master.php.net/note/edit/92870 Del: integrated -- https://master.php.net/note/delete/92870/integrated Del: useless -- https://master.php.net/note/delete/92870/useless Del: bad code -- https://master.php.net/note/delete/92870/bad+code Del: spam -- https://master.php.net/note/delete/92870/spam Del: non-english -- https://master.php.net/note/delete/92870/non-english Del: in docs -- https://master.php.net/note/delete/92870/in+docs Del: other reasons-- https://master.php.net/note/delete/92870 Reject -- https://master.php.net/note/reject/92870 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159372) next »