PHP Ping ip with ping command

Source: Internet
Author: User
Tags time in milliseconds

Actually, it's simple.

 <?php /**  * @param   $ip  target ip  * @param   $times   Ping times  */ function ping ($ip, $times =4)  {         $info  = array ();       if (!is_numeric ($times)  | |    $times -4<0)       {             $times  = 4;      }       if  (path_separator== ': '  | |  directory_separator== '/')//linux      {            exec ("ping  $ip  -c  $times", $info);            if  (Count ($info)  < 9)             {             $info [' Error ']= ' timeout ';        }  }   Else //windows  {       exec ("ping  $ip  -n $ Times ", $info);       if  (count ($info)  < 10)         {          $info [' Error ']= ' timeout ';        }  }  return  $info; }  $ip  =   ' 127.0.0.1 ';//ip address  print_r (ping ($IP));? >

The results are as follows:

Array (    [0] =>     [1] =>  is  ping  127.0.0.1  data with  32  bytes:    [2] =>  from  127.0.0.1  The reply:  bytes =32  time <1ms TTL=64    [3] =>  from  127.0.0.1  The reply:  bytes =32  time <1ms TTL=64    [4] =>  from  127.0.0.1  The reply:  bytes =32  time <1ms TTL=64    [5] =>  from  127.0.0.1  The reply:  bytes =32  time <1ms TTL=64    [6] =>      [7] => 127.0.0.1   Ping  Statistical Information:    [8] =>       Packet:  sent  = 4, received  = 4, lost  = 0  (0%  lost),     [9] =>  estimated time in milliseconds for round trip:    [10] =>       Shortest  = 0ms, longest  = 0ms, average  = 0ms) 

Try doing it!

PHP Ping ip with ping command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.