Log in

View Full Version : Server Status Online/Offline



YourGreatestMember
12-20-2008, 12:24 AM
Tried several more methods they all for me.. don't work.


For example the one below says it's offline


<?php

$server_host = "http://www.google.com";
$server_port = 80;

$conn = @fsockopen($server_host, $server_port, $errno, $err_string, 10);
if($conn === false) {
// server is offline
echo 'Server appears to be offline';
}
else {
// server is online
echo 'Server Online';
}

?>

YourGreatestMember
12-23-2008, 11:45 AM
Still can't get it going...

EDIT: Where's my original post gone??

bluewalrus
12-24-2008, 05:27 PM
This worked for me...


<?php

$conn = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if($conn === false) {
// server is offline
echo 'Server appears to be offline';
}
else {
// server is online
echo 'Server Online';
}

?>

benslayton
12-24-2008, 06:49 PM
What hosting company are you using?

Some host do not allow things like this....

diltony
12-24-2008, 07:27 PM
Try this one:
<?php
###local server_name => 127.0.0.1,localhost or computername
function sonline() {if ($_SERVER['SERVER_NAME']=="localhost"||$_SERVER['SERVER_NAME']=="127.0.0.1"||strtolower($_SERVER['SERVER_NAME'])==strtolower(getenv('COMPUTERNAME'))) {return false;} else {return true;}}

if(sonline()) {echo "Hooray, i am online, its xmas!";} else {echo "No way, i'm offline and it's boxing day already!";}
?>

thetestingsite
12-24-2008, 07:29 PM
That only works for the local server, I think the OP is trying to see the status of remote servers. The code that bluewalrus posted should work; however, benslayton is also correct due to the fact that it depends on the settings of the hosting server. They may or may not allow doing this.

djr33
12-24-2008, 08:10 PM
The only way around it if you can't use something like that would be to get a remote file another way and see if it loaded, like an image. If you can't even work that out (due to restrictions on remote urls), then you could even do it using Javascript, just by loading an image (a very small test, maybe 10x10px, or even just 1x1), then if that works go ahead and if not loop through the next servers until one does work.

diltony
12-30-2008, 11:41 PM
You can use an ajax http post request, look at the return status code, 401,404.....to determine if the server is available, that should do it.

Medyman
12-30-2008, 11:53 PM
You can use an ajax http post request, look at the return status code, 401,404.....to determine if the server is available, that should do it.

I was going to suggest the same thing. It's actually quite simple. I ran across this page (http://usernamecheck.com/) a few days ago (via Subtraction.com (http://www.subtraction.com/2008/12/18/username-check)). It uses a similar technique to check if a particular username is available at various sites.

diltony
12-31-2008, 04:01 PM
I tried the direct ajax method, failed cos i forgot to that ajax cannot cross domains directly, so i had to add a few lines of php code.
i posted the solution on http://www.dynamicdrive.com/forums/showthread.php?t=40179
the main engine is the php script, as usual i added an ajax interface to it.

hmsnacker123
01-08-2009, 08:04 AM
Try this:

<?php
require 'Net/Ping.php';
$ping = new Net_Ping;

if($ping->checkhost('www.example.com')){
echo "Reachable";
}else {
echo "Unreachable";
}
?>

You must have php installed, As well as PEAR.
Change the URL into your desired one.

tonyroberts09
01-08-2009, 06:22 PM
if that works go ahead and if not loop through the next servers until one does work.