How do I force a 'timeout' in a loop for that itteration, or conversley how to timeout a 'ping" request?

From: Date: Fri, 07 Feb 2003 23:56:12 +0000
Subject: How do I force a 'timeout' in a loop for that itteration, or conversley how to timeout a 'ping" request?
Groups: php.general 
Request: Send a blank email to php-general+get-134834@lists.php.net to get a copy of this message
I'm trying to automate finding pingable domains given an IP or a domain. The problem is that some domains don't actually return "pings", and on Linux, it just sits there forever (ugh!). So... Can someone tell me how to 'abort' or 'timeout' an itteration of a loop. Maybe start a timer and then check if a number of millis has gone by? But it seems that won't work b/c PHP isn't threaded, it will just hang at the exec() command right? Converseley, anyone know how to force a /bin/ping to automatically timeout (sans hitting CTRL+C)? I 'man ping' but it didn't seem to have that option. Here is the code I'm using... $typeArray = array ( 'www' => false, 'ftp' => false, 'mail' => false, 'exchange' => false, 'owa' => false, 'dns' => false, 'dns1' => false, 'dns2' => false, 'dns3' => false, 'router' => false, 'firewall' => false, 'fw' => false, 'fw1' => false, 'sql' => false, 'db' => false, 'database' => false, 'crm' => false ); reset($typeArray); while ( list($key, $val) = each($typeArray) ) { $testDomain = $key.".".$domain; $pingtest = exec("/bin/ping -c 1 -q ".$testDomain); //echo "<I><FONT SIZE=-3>pingtest of ".$testDomain." = ".$pingtest."</FONT></I><BR>\n"; if ( strstr($pingtest,"rtt min") ) { $typeArray[$key] = gethostbyname($testDomain); echo "<INPUT TYPE='checkbox' NAME='IPcheckbox[]' VALUE='".$typeArray[$key]."' CHECKED>".$testDomain." (".$typeArray[$key].")<BR>\n"; $ipCounter++; } //sleep(3); } if ($ipCounter == 0) echo "<B>No pingable domains found in our test list</B><BR>";

« previous php.general (#134834) next »