March 1st in PHP Scripts by .

PHP script to check server status online/offline

i wrote a simple php script to check whether the website or Ip address is online or offline. All you have to do is specify a website url or ip address and the script will return with ONLINE or OFFLINE. I used php fsockopen() to accomplish this.

/* Usage:
$status =  GetServerStatus('http://domain.com',80)
or
$status =  GetServerStatus('IPAddress',80)
*/

<?php
function GetServerStatus($site, $port)
{
$status = array("OFFLINE", "ONLINE");
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
    return $status[0];
} else
  { return $status[1];}
}
?>

If you want to ping a server to check connectivity, you can use php ping scripts.

Similar Posts:

12 Comments

  • Austin
    March 5, 2009
  • R
    March 30, 2009
  • shafiq issani
    October 14, 2009
  • Dan
    March 21, 2010
  • herbata
    December 5, 2010
  • Goat
    February 20, 2011
  • dynamic
    June 11, 2011
  • Mark Lunn
    July 5, 2011
  • Dynamic
    August 17, 2011
    • Steen
      December 30, 2011
  • Arshad Ansari
    December 9, 2011
  • Kevin
    January 25, 2012

Leave A Comment.