Realtime ping monitor using php

Dear all

i want to see the ping status using php script.
i want to show this as like in command prompt.

Example: if i execute ping 127.0.0.1 -t cammand in cmd and get ping response it will show

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

it will continue either i stop this and we will see the ping response in real time

is this possible in php?
please help me.

You can wrap something like this in a loop…

[php]<?php
$output = shell_exec(‘ping -c1 google.com’);
echo “

$output
”;
?>[/php]

Dear TOPCOADER

as per your code it shows an error massege

BAD Command -c1

Hello,

Just take out the -c1 and it should work. the following is the syntax for the ping command (not sure where topcoder got -c flag from):

ping [-t] [-a] [-n Count] [-l Size] [-f] [-i TTL] [-v TOS] [-r Count] [-s Count] [{-j HostList | -k HostList}] [-w Timeout] [TargetName]

Source

Cheers!

Linux :slight_smile:

Usage: ping [-LRUbdfnqrvVaAD] [-c count] [-i interval] [-w deadline] [-p pattern] [-s packetsize] [-t ttl] [-I interface] [-M pmtudisc-hint] [-m mark] [-S sndbuf] [-T tstamp-options] [-Q tos] [hop1 ...] destination

JimL,

It completely slipped my mind about the Linux syntax so thank you for that. Also, since the OP says that his system couldn’t understand -c tells me that he’s probably using a windows web server so hopefully my syntax can assist him.

Cheers!

Sponsor our Newsletter | Privacy Policy | Terms of Service