如何使用PHP在我的PING中获得往返时间

So i have this code that whenever an IP is ping able or up it'll choose the green line to appear on my screen and in reverse the red line. So what I am trying to do instead if the Round Trip Time of that IP is < 200 then it's green and when it's > 250 it's red . How can i do that? Anyone help me. Thank you.

<?php
$page = $_SERVER['PHP_SELF'];
$sec = 5;

function pingAddress($TEST) {
    $pingresult = exec("ping -c 1 $TEST", $output, $result);

    if ($result == 0) {
        echo "Ping successful!";
        echo "<pre>Your ping: $TEST</pre>";
        echo "<hr color = \"green\" width = 40%> GOOD";
    } else {
        echo "Ping unsuccessful!";
        echo "<pre>Your ping: $TEST</pre>";
        echo "<hr color = \"red\" width = 40%> BAD";
    }
}  
pingAddress("66.147.244.228");
?>

<html>
<head> 
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo   $page?>'">
</head>
<body> 
</body>
</html>

The exec function is ok to use, but you should parse the contents of the output argument, after declaring it first as an array. Even if you added -c 1 to only issue one ping, this is the recommended way of using exec.

define('RETRIES', 1);
define('PING_PATH', '/usr/bin/ping');

function pingAddress($IP)
{
    $output = array();
    exec(PING_PATH . " -c " . RETRIES . " $IP", $output);

    // generic way, even for one line. You can also do -c 4,
    // and preg_match will pick the first meaningful result.

    $output_string = implode("; ", $output); 

    /// adapt the regular expression to the actual format of your implementation of ping
    if (preg_match('/ time=\s+(\d+)ms/', $output_string, $bits)) {
        $rt_time = (int)$bits[1];

        if ($rt_time < 200) {
            // green business
        }
        else if ($rt_time > 250) {
            // red business
        }
        else {
            // default handler business (or not...)
        }
    }
    else {
        echo "Hum, I didn't manage to parse the output of the ping command.", PHP_EOL;
    }

}