PHP script ping online/ofline via web server?

Status
Not open for further replies.

MediaStar

Active Member
2,664
2010
446
235
Hello guys, i found this script from google.

Code:
[COLOR=#000000]<?php[/COLOR]
if (!$socket = @fsockopen("IP.HERE", 80, $errno, $errstr, 30))
{
  echo "<font color='red'><strong>Offline!</strong></font>";
}
else 
{
  echo "<font color='green'><strong>Online!/strong></font>";
  

  fclose($socket);
}
 [COLOR=#000000]?>[/COLOR]

The code is working fine. I want add a few function from this script:

1) Auto ping every 25sec or something (im not sure what function $errstr, 30)) from the script)
2) Send notification to emel when the IP/Server was down

Is there any pro php here? Thanks.
 
4 comments
I'm just curious, how are you using this?

I used to have this app for my chumbyone that would poll a webserver (that had a php file placed on it for the app). If it wasn't able to communicate with the php file it would make the chumbyone ring an awfully annoying sound to alert you.

Unfortunately my chumbyone broke, they went outta business, and when I finally got around to getting a new one the app vanished from the internet.

So I'd be curious if your using this on some sorta device that makes an audible alarm or anything of that sort.

I'm not a PHP wiz so unfortunately there isn't much I'd be able to help you with on your specific request, but this is something that I've been wanting to get around to doing for some time now. So if you or anyone else knows of any type of app that works like this & can be installed on a tablet, or even a linux system (my second and third PCs are ubuntu server 14.04) I would be greatly interested!
 
If you are running this from a linux server/vps use cron task to run it every ?? minutes.

To add sending an email this should work for you just change it to your email address.
Code:
<?php
if (!$socket = @fsockopen("IP.HERE", 80, $errno, $errstr, 30))
{
    echo "<font color='red'><strong>Offline!</strong></font>";
    $msg = "Your Site is offline : ".date("Y/m/d h:i:s a");
    mail("You@youremail.com","Site Offline!",$msg);
}
else 
{
  echo "<font color='green'><strong>Online!/strong></font>";
  fclose($socket);
}
 ?>
 
Last edited:
Status
Not open for further replies.
Back
Top