sjohnson at fuzzygroup dot com
17-Mar-2002 02:27
<?php
//script to see if host exists on
Internet
//following up on the above point about host name
//checking and SQL timeouts, run this test script
//and see how long
it takes for 2nd call to
//hostname check to fail
//NOTE -- not
PHP's fault -- nature of DNS
//A known good dns name (my
own)
$nametotest = "fuzzygroup.com";
//Call address
test function
testipaddress($nametotest);
//A known bad name
(trust me)
$nametotest = "providence.mascot.com";
//Call
address test function
testipaddress($nametotest);
//ip address
checking function
//for real use should have a return value but example
code
function testipaddress ($nametotest) {
$ipaddress =
$nametotest;
$ipaddress = gethostbyname($nametotest);
if
($ipaddress == $nametotest) {
echo "No ip address for host, so
host "
. "not currently available in DNS and
"
. "probably offline for some
time
";
}
else {
echo "good hostname, ipaddress =
$ipaddress
";
}
}
//Recommended fix for sql
applications:
// store url to temporary table
// run second process
periodically to
// check urls and update main table
?>