VB icon

^!!~ Check if a service/machine is alive ~!!^

Email
Submitted on: 1/1/2015 10:34:00 PM
By: fritz0x00 (from psc cd)  
Level: Advanced
User Rating: By 6 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 2272
 
     Check and see if a service is up or down on a certain machine. Useful for alot of things, say you have MSN Messenger or AIM, you can have a script check YOUR IP address and the MSN or AIM port number and then let the users at your website know if your online or not! Can also be useful if you use alot of file mirrors for your website and want to check if there up or down. Infinite amount of uses! Really fun, simple, easy to use, and useful for many things. Well commented.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: ^!!~ Check if a service/machine is alive ~!!^
// Description:Check and see if a service is up or down on a certain machine.
Useful for alot of things, say you have MSN Messenger or AIM, you can have a script check YOUR IP address and the MSN or AIM port number and then let the users at your website know if your online or not! Can also be useful if you use alot of file mirrors for your website and want to check if there up or down. Infinite amount of uses! Really fun, simple, easy to use, and useful for many things. Well commented.
// By: fritz0x00 (from psc cd)
//
// Inputs:$address, $service
//
// Assumes:Don't forget to change $address and $service, doh!
//
// Side Effects:If you forget to turn off error reporting(error_reporting(0);), you will get a 'Warning' if fsockopen fails to connect.
//**************************************

<?php
error_reporting(0); //** Turn error reporting off so we don't get the unneeded warning message if we fail to connect, we will handle that our selfs
$address = "127.0.0.1"; //** Address of the machine
$service = 80; //** Service or Port number, in this case 80 for the HTTPD daemon... say we want to have a page to check if our webserver is up
//** fsockopen returns a boolean value upon execution, depending if it fails(returns FALSE or NULL) or not(returns TRUE)
if(fsockopen($address, $service)) //** If we can connect...
{
 //** Address is up, do what you want here
 echo "$address:$service is up!";
}
else //** We can't connect!
{
 //** Address is NOT up, do what you want here
 echo "$address:$service is NOT up!";
}
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.