RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About Me
  • My Publications
  • My Work Domain
  • phpResource Feeds
  •  

    “ping” in PHP

    Get your pinging result by PHP like this way:

    —————————————–

    < ?php
    $arr = array();
    exec("ping -c 2 www.google.com", $arr); //2 packets
    dBug($arr);

    function dBug($dump)
    {
    echo "<PRE>";
    print_r($dump);
    echo "</PRE>";
    }
    ?>
    —————————————–

    I got this result:

    —————————————-
    Array
    (
    [0] => PING www.l.google.com (64.233.189.104) 56(84) bytes of data.
    [1] => 64 bytes from 64.233.189.104: icmp_seq=0 ttl=245 time=608 ms
    [2] => 64 bytes from 64.233.189.104: icmp_seq=1 ttl=245 time=519 ms
    [3] =>
    [4] => — www.l.google.com ping statistics —
    [5] => 2 packets transmitted, 2 received, 0% packet loss, time 2755ms
    [6] => rtt min/avg/max/mdev = 519.180/563.682/608.185/44.508 ms, pipe 2
    )
    —————————————-

    Someones asked me this type of questions( related to checking connectivity by PHP). This one is my solution for now.

    Regards,
    [Rupom]

    2 Responses to ““ping” in PHP”

    1. Sizar Says:

      Good option to see ping result by php script.

    2. shimul Says:

      Cool script. Actually PHP supports many efffective works with its simple functionality. But most of us donno the depth of uses for those functionality. Enjoy PHPing…..

    Leave a Reply

    You must be logged in to post a comment.