Forum Moderators: coopster
$ping_ex = exec("ping 72.3.232.139", $ping_result, $pr);
if (count($ping_result) > 1){
echo 'Ping online - response';
} else {
echo 'Ping offline - response';
}
Note that there might be actual delays before the results appear.
Habtom
string exec ( string $command [, array &$output [, int &$return_var ]] )
exec() executes the given command .command - The command that will be executed.
output - If the output argument is present, then the specified array will be filled with every line of output from the command.
return_var - If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.
Thanks!
Yup you are right. This one works. But their is a problem. I tired a following script
<?
$ping_ex = exec("ping -c2 192.168.2.45", $ping_result, $pr);
if (count($ping_result) > 1){
echo 'Ping online - response';
} else {
echo 'Ping offline - response';
}
?>
It prints "Ping online - response" in both cases weather the system is online or not. Not sure if this condition has a problem
" if(count($ping_result) > 1) "
Regards,
Qasim
Example -
ping -c2 nothere_aklsjdhflsakjflkasjdf_example.com
ping: unknown host nothere_aklsjdhflsakjflkasjdf_example.com
ping -c2 example.com
PING example.com (208.77.188.166) 56(84) bytes of data.
64 bytes from www.example.com (208.77.188.166): icmp_seq=1 ttl=52 time=165 ms
64 bytes from www.example.com (208.77.188.166): icmp_seq=2 ttl=52 time=157 ms
--- example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 157.295/161.213/165.132/3.939 ms