ping - PHP pinging, even 1 request timeout -
i have been using script below, however, want ping 3-4 times, , within 3-4 times if has single request timeout, want php come failed.
here's script i'm using:
<?php function pingaddresshasneverfailed($tries) { ($i = 0; $i < $tries; $i++) { $pingresult = shell_exec("ping -c 1 www.google.com", $outcome, $status); if ($status != 0) homecoming false; } homecoming true; } if (pingaddresshasneverfailed(3)) { echo "uoc gi"; } ?>
please help if can, give thanks much in advance!
if ping fails (in set) not have 0%
in output (i.e. 0%
packet loss), same linux , windows:
function ping($host, $times = 3) { exec("/bin/ping -c 3 $host", $out, $status); homecoming $status === 0 && false !== strpos(join('', $out), '0%'); } if (ping('www.google.com)) { echo "yay\n"; } else { echo "oh dear\n"; }
you may have adjust ping
arguments fit environment , create sure host name sanitized.
php ping
No comments:
Post a Comment