PHP Server Status using fsockopen


On the page you want to put the server status, put this code:

PHP Code
  1. <?php
  2. $churl = @fsockopen("IPADDRESS", PORT, $errno, $errstr, 5);
  3.  
  4. if(!$churl) { // Unable to open socket
  5. $statusMSG = "OFFLINE MESSAGE";
  6. } else {
  7. $statusMSG = "ONLINE MESSAGE";
  8. }
  9.  
  10. ?>


Instructions:
  • Replace IPADDRESS with the server's IP address.
  • Replace PORT with the port the server is running on.
  • Replace OFFLINE MESSAGE with the message you want displayed when the server is offline. This can include plain text or HTML.
  • Replace ONLINE MESSAGE with the message you want displayed when the server is online. This can also include plain text or HTML.




Then, where you want the message to appear, put this:
PHP Code
  1. <?php
  2. echo $statusMSG;
  3. ?>
Xerofait's Avatar
Author:
Views:
2,280
Rating:
Posted on Friday 16th May 2008 at 01:43 PM
jambomb
jambomb's Avatar
NICE!