Not sure on linux, but on freebsd ping's man page says:
-t timeout Specify a timeout, in seconds, before ping exits regardless
of how many packets have been recieved.
On Fri, 7 Feb 2003, Daevid Vincent wrote:
> 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>";
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php