0

This is what I currently have. It doesn't work, what needs to be done to fix it?

<?php
$status =  GetServerStatus('http://domain.com',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];
    }
}
?>
4
  • Does your server support sockets? Are you runnong this on a free web host? Commented Dec 15, 2012 at 2:46
  • What does "It doesn't work" mean? Please provide more detailed information and errors. Commented Dec 15, 2012 at 2:46
  • For a start, remove the @ from in front of fsockopen to see if there are errors or warnings being suppressed. Also remove the 2 parameter so that you can see if it is taking longer to connect to the server. This is possible especially if the server is busy and/or you have DNS issues and you're using a hostname. Commented Dec 15, 2012 at 2:48
  • Using the @ stop error output. Getting rid of that would help. us3.php.net/manual/en/language.operators.errorcontrol.php Commented Dec 15, 2012 at 2:52

1 Answer 1

1

You don't put in the http:// part.

echo GetServerStatus('www.domain.com', 80);

function GetServerStatus($site, $port)
{
    $fp = @ fsockopen($site, $port, $errno, $errstr, 2);
    return ($fp)
        ? 'ONLINE'
        : 'OFFLINE';
}

Fist parameter should be a hostname not a URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.