是否有能够Ping IP地址的PHP脚本可用

是否有能够Ping IP地址的PHP脚本可用,php,Php,我想问的是,是否有任何php脚本可以ping一个IP地址,如果是这样,让我知道我们可以如何做到这一点 $ip = "127.0.0.1"; exec("ping -n 3 $ip", $output, $status); print_r($output); 输出将是一个数组。大概是这样的: Array ( [0] => [1] => Pinging 127.0.0.1 with 32 bytes of data: [2] => Reply fro

我想问的是,是否有任何php脚本可以ping一个IP地址,如果是这样,让我知道我们可以如何做到这一点

$ip =   "127.0.0.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);
输出将是一个数组。大概是这样的:

Array
(
    [0] => 
    [1] => Pinging 127.0.0.1 with 32 bytes of data:
    [2] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    [3] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    [4] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    [5] => 
    [6] => Ping statistics for 127.0.0.1:
    [7] =>     Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
    [8] => Approximate round trip times in milli-seconds:
    [9] =>     Minimum = 0ms, Maximum = 0ms, Average = 0ms
)
数组
(
[0] => 
[1] =>使用32字节数据ping 127.0.0.1:
[2] =>127.0.0.1的回复:字节=32次127.0.0.1的回复:字节=32次127.0.0.1的回复:字节=32次
[6] =>127.0.0.1的Ping统计信息:
[7] =>数据包:发送=3,接收=3,丢失=0(0%丢失),
[8] =>近似往返时间(毫秒):
[9] =>最小值=0毫秒,最大值=0毫秒,平均值=0毫秒
)

在linux上,您可以使用以下命令:

<?php
    function ping($ip) {
        $result = exec("/bin/ping -n 3 $ip", $outcome, $status);
        if (0 == $status) {
            $status = "alive";
        } else {
            $status = "dead";
        }
        echo $status;
    }

    ping("80.80.80.80");

?>

每30秒复制一次?即使没有收到请求?您确定要在PHP中执行此操作吗?