What is the best way to ping anIP in php and determine if it is live or not?
Thanks!
Ping ip in php
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Ping ip in php
PHP doesn't have even the slightest ability to send icmp packets (ping).GeXus wrote:What is the best way to ping anIP in php and determine if it is live or not?
Thanks!
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
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
wtf wrote:PEAR Net_Ping will do the job
Does that use shell commands or native PHP code? Sorry, I havent looked at it but figured you might already know.
You can always use this (if its what your trying to accomplish...
Hope that helps!
Code: Select all
if(!fopen("http://www.your-url_or_your-ip-here","r")){
Take some action! (IE -- Page yourself)
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.siefkencp wrote:You can always use this (if its what your trying to accomplish...
Hope that helps!Code: Select all
if(!fopen("http://www.your-url_or_your-ip-here","r")){ Take some action! (IE -- Page yourself) }