php ping script
I want to do a script that echoes 1 if a host responds to ping and 0 if the host doesn't.
Any ideea on how to do that ? |
hope i'm not talking by myself :)
Code:
<? |
Hi
Im trying to do something very similar. I wrote a script that returns the ping time if it gets a reply, and NULL if ping times out. My problem is that if i dont get a reply the script takes about 10 seconds to time out. Im making this script for a status page of a wireless lan with about 200 units so u see why this is a problem. Any ideas?? Did u get the script to work?? Ill post the script when i get home from work if u're interested. sic |
I have done the same to see if my internet connections are up or not. The script is written in Bash.
The timeout problem can be solved by specifying the -w or -W ping option. Maybe not necessary in your application of detecting wireless clients, but usually I recommend to check more than one ping reply using the count option. If there are routers or Cisco managed bridges in between your hosts the first ping might fail. jlinkels |
I have tried -w and -t with no luck.
The shell_exec command stil uses 10 seconds to timeout at each offline router. The funny thing is that it works fine on windows. |
Weird.... I am using this code, and when I specify "-w 1" the script returns in exactly 1 second. When I don't use -w it takes 10 seconds.
Are you sure you use lower case "w" I use php5-cli to run this script. jlinkels Code:
<? |
I think it's cause I use debian. Ping in debian doesn't have -w.
I wouldn't know(i'm a :newbie: ) but someone told me so. I think there is something called fping with more options. Anyway here's the code: Code:
function ping($ip){ |
I use debian as well.
Try: Code:
linkels@jlinkels_pc:/tmp$ ping -h Code:
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline] Code:
"$ time ping -c 1 -w 1 $ip" jlinkels |
I tried that but the -w parameter just isn't there. Maybe it's the version or something. I got our admin to install fping on the server. He should be done later today. I'll let u know how it went.
The shell_exec command i used is just the last desperate try in an endless line of tries. And i think the one u're using was the first one. But thanx for trying. sic |
All times are GMT -5. The time now is 03:13 PM. |