SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Sunday, May 22, 2011

How to Show if your server is Online or Offline?

One way to try to find out if a server is online is to try and open a socket connection to the server. If the connection fails, one can assume that the server is down (although the problem can be somewhere else too).

Check out this function and read all the user comments:

Here's a very simple demonstration of php code:
<?php if (fsockopen('www.yourserver.com', 80)){     
echo(
'The server in online');  

} else{  
 
echo(
'The server in offline');  
?>
The first parameter is the IP address of the server you want to check (in this case, www.yourserver.com, it could also be something like 111.222.333.444). The 80 is the port number (for HTTP), which can sometimes be different (21 for FTP etc.).

No comments:

Post a Comment