Page 1 of 1

Ping ip in php

Posted: Fri Jul 21, 2006 12:08 pm
by GeXus
What is the best way to ping anIP in php and determine if it is live or not?

Thanks!

Posted: Fri Jul 21, 2006 12:43 pm
by wtf
PEAR Net_Ping will do the job

Re: Ping ip in php

Posted: Fri Jul 21, 2006 12:44 pm
by Chris Corbyn
GeXus wrote:What is the best way to ping anIP in php and determine if it is live or not?

Thanks!
PHP doesn't have even the slightest ability to send icmp packets (ping).

The best you can do is either:

a) Try to use fsockopen() on a certain port if you're only needing to know about a given port
b) Execute ping via the shell commands

;)

Posted: Fri Jul 21, 2006 12:45 pm
by Chris Corbyn
wtf wrote:PEAR Net_Ping will do the job
:) Cool.

Does that use shell commands or native PHP code? Sorry, I havent looked at it but figured you might already know.

Posted: Fri Jul 21, 2006 12:47 pm
by siefkencp
You can always use this (if its what your trying to accomplish...

Code: Select all

if(!fopen("http://www.your-url_or_your-ip-here","r")){

Take some action! (IE -- Page yourself)

}
Hope that helps!

Posted: Fri Jul 21, 2006 12:49 pm
by Roja
d11wtq wrote:Does that use shell commands or native PHP code? Sorry, I havent looked at it but figured you might already know.
It exec's shell commands.

Posted: Fri Jul 21, 2006 12:51 pm
by feyd
siefkencp wrote:You can always use this (if its what your trying to accomplish...

Code: Select all

if(!fopen("http://www.your-url_or_your-ip-here","r")){

Take some action! (IE -- Page yourself)

}
Hope that helps!
That would, at best, tell you if the URL or IP responds to HTTP requests. Failing does not mean that it does not exist or isn't live unfortunately.