March 1st in PHP Scripts by pbu .

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:

Share and Enjoy:
  • del.icio.us
  • digg
  • StumbleUpon
  • Technorati
  • DZone
  • Facebook
  • FriendFeed
  • Reddit
  • RSS
  • Twitter

4 Comments

  • Austin
    March 5, 2009
  • R
    March 30, 2009
  • shafiq issani
    October 14, 2009
  • Dan
    March 21, 2010

Leave A Comment.