美文网首页
PHP PING值函数

PHP PING值函数

作者: hel2o | 来源:发表于2016-08-09 17:14 被阅读0次

PHP PING值函数

直接返回结果

function ping($ip,$times)
 {  
    $ping = array();
    $find = array();
    $time = date("Y-m-d H:i:s");
    exec("ping $ip -c $times -i 1 -w 1",$ping);
    print_r($ping);
    if (count($ping) <= 5)
           {
            $result='连接超时!'.count($ping);
        }
    else
        {                        
            $strall = substr($ping[count($ping)-1],22);
            $pos1 = strpos($strall,'/');
            $pos3 = strrpos($strall, '/');
            $str1 = substr($strall, 0, $pos3);
            $pos2 = strrpos($str1, '/');
            $find['min'] = substr($str1, 1, $pos1-1);
            $find['avg'] = substr($str1, $pos1+1, $pos2-$pos1-1);
            $find['max'] = substr($str1, $pos2+1);
            $result = 'Ping结果:'."\n".'最小:'.$find['min']."\n".'最大:'.$find['max']."\n".'平均:'.$find['avg']."\n\n".$time;                
        }
    return $result;
}

相关文章

  • PHP PING值函数

    PHP PING值函数 直接返回结果

  • php函数如何返回引用?

    通过对Python的函数返回值返回的是值还是引用?的研究,引发了我对于php的函数返回值的思考:在php中,函数的...

  • PHP数组处理函数:in_array() -- 内置函数

    所用PHP环境:7.1.16 函数简介 此函数检查数组中是否存在某个值返回值为 布尔(boolean) 类型的值 ...

  • php json记录

    1:PHP json_encode()函数用于在PHP JSON编码。这个函数成功返回JSON表示的值,失败则返回...

  • PHP之each()函数输出空白问题

    each()函数 (PHP 4, PHP 5, PHP 7) each — 返回数组中当前的键/值对并将数组指针向...

  • 九月二号

    PHP函数之可变函数 所谓可变函数,即通过变量的值来调用函数,因为变量的值是可变的,所以可以通过改变一个变量的值来...

  • PHP语法

    PHP语法 php基本语法 isset函数如果 var 存在并且值不是 NULL 则返回 TRUE,否则返回 FA...

  • ini_set 函数

    PHP ini_set用来设置php.ini的值,在函数执行的时候生效,脚本结束后,设置失效。无需打开php.in...

  • PHP中echo(),print(),print_r()有什么区

    echo是php语句,print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用)print(...

  • PHP全栈学习笔记24

    PHP in_array() 函数 定义和用法in_array() 函数搜索数组中是否存在指定的值。 type 参...

网友评论

      本文标题:PHP PING值函数

      本文链接:https://www.haomeiwen.com/subject/lmsdsttx.html