PDA

View Full Version : Ping Question




bobber205
Aug 26, 2006, 08:57 PM
Whenever I ping an address through PHP (the exec command) and when it's hte second time or more since I've done the same command, I get something like this.

round-trip min/avg/max/stddev = 3.917/3.917/3.917/0.000 ms

Which is NOT what I want. Any suggestions?

or comments. There must be something I'm missing.

EDIT:
Ooh! It's not just giving me the above line, but instead exec is giving back just the last line.


3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 79.492/80.872/82.678/1.335 ms


Any idea on how to stop this?



Eraserhead
Aug 27, 2006, 05:57 AM
That looks like what you get in Terminal...

Last login: Sun Aug 27 11:56:05 on ttyp1
Welcome to Darwin!
Vigor14:~ Matthew$ ping -c 2 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=255 time=0.592 ms
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.646 ms

--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.592/0.619/0.646/0.027 ms
Vigor14:~ Matthew$ ping -c 2 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=255 time=0.644 ms
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.534 ms

--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.534/0.589/0.644/0.055 ms
Vigor14:~ Matthew$


The -c 2 limit's it to sending 2 pings

savar
Aug 27, 2006, 07:42 PM
Which is NOT what I want. Any suggestions?

What do you want??

Any idea on how to stop this?
grep, sed, preg_replace()...hard to say since I don't understand what your actual goal is here.

bobber205
Aug 28, 2006, 10:13 AM
sorry.

What I actually want it is all the text from the exec command being able to be stored in a variable.

savar
Aug 28, 2006, 07:01 PM
sorry.

What I actually want it is all the text from the exec command being able to be stored in a variable.

Oh. Can you post the exact code that you're trying to use? Also, try using system() instead of exec(). This works on a server that I'm using at the moment:


[atmeweb@boxwood bin]$ cat test.php
<?php
echo(system("nslookup google.com"));
?>

[atmeweb@boxwood bin]$ php-cli test.php
Server: 64.29.16.113
Address: 64.29.16.113#53

Non-authoritative answer:
Name: google.com
Address: 72.14.207.99
Name: google.com
Address: 64.233.167.99
Name: google.com
Address: 64.233.187.99


You can also pass an array into exec to get lines of output stored in an array.
http://us2.php.net/function.exec