hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Programming Tutorials : Checking Your Server Status
Reply

Programming Tutorials How-Tos related to programming, databases, and the like.
Forum Jump

Checking Your Server Status

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-11-2005, 07:39 AM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
Arrow

Checking Your Server Status


This a pretty simple script that will check the status of your server, or it can be used so that anyone can enter the IP or domain of there server and it will check all the common ports.

Here is an example:
http://status.eX13.net

The Code:
PHP Code:
<?php $up = @fsockopen("$ip"80$errno$errstr30);  
if(
$up
{  
   echo 
'Online';  

else 
{
   echo 
'Offline'
?>
ok well simple all this does is open a connection to "$ip" on port 80, and then if $up (if the connection was successful) it will echo Online if not it will echo Offline.

If you wanted to use the code for just one server you can replace $ip with either the domain name or the IP. If using the domain name you do not include http:// you would just type domainname.com

The $errno and $errstr are both standard error parameters. The last number "30" is how long the connection should stay open until it is classed as timed out.

If you wanted to make it so that anyone can check the status of there site all you would do is at the top of the page add:

PHP Code:
$ip$_POST['ip'];
if(
is_null($ip))
{
die();
}
else
{
 echo 
"Server Status Report For $ip"
 } 
What this does is retrieve the posted variable "$ip" and checks if the variable is empty if nothing was entered the script will terminate if something is entered the script will simply carry on what it is meant to be doing.

Now all that needs to be done is too add a form at the top of the page. The form needs a textbox field and a submit button.

PHP Code:
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
  <div align="center">
<p>
      <input name="ip" type="text" value="">
      <input type="submit" name="Submit" value="Submit">
</p>
This form will show a text box where anyone can enter any the domain or IP and then when the Submit button is click it will post the data into its self using the command:

action="<?php echp $_SERVER['PHP_SELF'] ?>"

Then the posted information will replace the variable $ip. You could use the code to show more than one port. By simply using the same "fsockopen" command but changing the Port number.

Heres a list of command ports:
HTTP - 80
FTP - 21
SSH - 22
MYSQL - 3306
CPANEL - 2082
WHM - 2086
POP3 - 110
SMTP - 25


Im sure this code will come in handy for someone.

Reply With Quote


Sponsored Links
  #2  
Old 04-12-2005, 06:23 AM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
Did anyone find this useful?

Reply With Quote
  #3  
Old 04-22-2005, 03:07 AM
VolkNet VolkNet is offline
Web Hosting Master
 
Join Date: Jun 2004
Location: Bay Area -USA
Posts: 1,738
Thank you! This is a cool little trick. I always wondered how to do that! Thank you for writing this.

Reply With Quote
Sponsored Links
  #4  
Old 05-05-2005, 07:51 PM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
No Probs Always happy to help!

Reply With Quote
  #5  
Old 05-05-2005, 07:57 PM
error404 error404 is offline
Web Hosting Master
 
Join Date: Dec 2004
Location: Canada
Posts: 1,076
With the given code, you're using a timeout of 30 seconds. In the case of a firewalled server or downed box, this function call will stall the drawing of your page for 30 seconds before failing. I'd recommend cutting the timeout down to one or two seconds so you don't inadvertently DOS yourself .

I'd be good practice and make it easier to use by dropping it into a function instead:
PHP Code:
function checkService($ip$port 80) {
   return @
fsockopen($ip$port$errno$errstr2);

Drop this at the top of your document, then where you want to display the status, do:
PHP Code:
<?= (checkService("localhost") ? "Online" "Offline"?>
Cheers!

Reply With Quote
  #6  
Old 05-12-2005, 12:18 AM
BurstChris BurstChris is offline
Newbie
 
Join Date: May 2005
Location: Scranton, PA
Posts: 21
you can also install sysmon and like tools instead of reinventing the wheel

they are more rich in features and better quality, worth checking out, as it can do more than just tcp connect()'s

Reply With Quote
  #7  
Old 06-14-2005, 03:03 PM
skyDesigner skyDesigner is offline
Disabled
 
Join Date: Jun 2005
Posts: 6
Wow...great, i will install it right now...at least..i will try...
It's good that still there is some people who wants to help others 4 free
Best regards

Reply With Quote
  #8  
Old 06-22-2005, 10:47 AM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
TCP Connects work And its only for simple use! For the people who need a quick bit of code.

Im glad some people like it

Reply With Quote
  #9  
Old 07-07-2005, 02:52 PM
ozone_mark ozone_mark is offline
Junior Guru Wannabe
 
Join Date: Feb 2005
Location: Ohio, USA
Posts: 54
BurstChris,

Can you give the site where i can download the Sysmon script ?

Thanks.

Reply With Quote
  #10  
Old 07-08-2005, 08:53 PM
jamesyeeoc jamesyeeoc is offline
Junior Guru
 
Join Date: Dec 2003
Location: Sunny So. Calif.
Posts: 204
Home page for sysmon:
http://www.sysmon.org/

Reply With Quote
  #11  
Old 07-09-2005, 10:35 AM
Bonza Bonza is offline
Newbie
 
Join Date: May 2005
Posts: 5
Excellent, I'm about to go install right now..!

Reply With Quote
  #12  
Old 07-10-2005, 03:02 AM
linux-tech linux-tech is offline
<?require_once("life")?>
 
Join Date: Sep 2002
Location: inside your network
Posts: 9,548
Sysmon is great for the first few months. After that, you actually want reports, and to be able to customize things.
Realistically, if you know php, then program your own app, this is always the best way. Then you can use your own app to do what you want it to do. If you don't, use one of the commercial applications such as alertra or whatnot that actually keep storage of data properly.

I used sysmon for about 6 months until it became too much of a hassle. People want shiny images and to be able to see what's going on, and verify that the server's actually up

Reply With Quote
  #13  
Old 07-10-2005, 04:59 AM
jamesyeeoc jamesyeeoc is offline
Junior Guru
 
Join Date: Dec 2003
Location: Sunny So. Calif.
Posts: 204
Quote:
I used sysmon for about 6 months until it became too much of a hassle. People want shiny images and to be able to see what's going on, and verify that the server's actually up
Yes, I agree, but to each their own It's always a learning curve...

Reply With Quote
  #14  
Old 07-11-2005, 01:23 AM
McJeff215 McJeff215 is offline
Junior Guru Wannabe
 
Join Date: Jul 2005
Posts: 62
Don't forget about OpenNMS, it will give you some of the more advanced NMS related features as opposed to a simple "up/down" message.

Also:

SiteScope
ipMonitor
Big Brother

The latter three will give you more of an up-or-down synthetic transaction apporoach, while the first will give you more of a classic NMS approach.

I've spent time at places where we've built NMS systems and at places where we've bought them. I feel a rant coming on, so if anyone is really interested, let me know. ;-)

Reply With Quote
  #15  
Old 07-16-2005, 12:39 PM
TrophyHost TrophyHost is offline
WHT Addict
 
Join Date: Jun 2005
Location: Northern Ireland
Posts: 100
Instead of saying "online" & "Offline" how do you get it to show images?

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Hivelocity Ordering System Shows Server Installation via Live Camera Feed Web Hosting News 2013-02-22 12:20:26
Web Host DiscountASP.NET Renews Microsoft Gold Hosting Competency Web Hosting News 2013-02-14 16:55:56
Web Host MochaHost Adds New Features to Linux VPS Hosting Plans Web Hosting News 2012-08-01 15:52:14
GlobalSign, DigiCert, Comodo Partner to Improve NGINX Server Security with OCSP-Stapling Method Web Hosting News 2012-06-20 12:21:06
Web Host eUKhost Moves Billing System to New Server After Hacker Breach Web Hosting News 2012-04-30 10:21:08


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?