if server_online = true
document.write ("server is ON line")
else
document.write ("server is OFF line")
endif
Can anybody present me the detail correct language? Thanks.
Teresa
So I'm moving this post from the HTML and Browsers forum over to the Server Side Scripting forum - I'll bet we can have an answer for you in no time.
You can do this by using the LWP::UserAgent.pm [search.cpan.org] module along with HTTP::Status.
use LWP::UserAgent;
use HTTP::Status;
my $ua = new LWP::UserAgent;
# define a User Agent and Timeout #
$ua->agent('My server cheker');
$ua->timeout(20);
# make the request
my $req = new HTTP::Request( GET => 'http://www.somesite.tld');
# check if server responds
my $response = $ua->request($req);
if ($response->is_success) {
print "Server is online";
} else {
print "Server is offline";
}
$fp = fsockopen ("www.example.com", 80, $errno, $errstr, 30);
$ua->timeout(20);
GeorgeGG
<EDITED>
Try this
file on-off.htm
<html><head><title>OnLine/OffLine</title></head><body>
<script TYPE="text/javascript">
var on_line = "No";
</script>
<script type="text/JavaScript" src="http://my_domain.com/on-line.js"></script>
<script TYPE="text/javascript">
if (on_line!= "No")
document.write("Server is online<br>");
else
document.write("Server is offline<br>");
</script>
</body></html>
file on-line.js
on_line = "Yes";
Still have problem with the time out if server is down...
I use a 1 second timeout for head requests/ftp checks and
other off server checks.
noSanity
if (on_line!= "No")
document.write("Server is online<br>");
else
document.write("Server is offline<br>");
Change to
if (on_line!= "Yes")
document.write("Server is offline<br>");
else
document.write("Server is online<br>");
Also do not change the 'var on_line = "No";'
nosanity
using javascript,
if the remote page is offline, the page loading is quite slow.
That is what's so bad about those JavaScript track/loggers
that are available...
You can probably drop the time down to 1 or 2 seconds,
I started off using 5 seconds on my sockets and finally settled on
1 second on everything on my pages and 10 for whois...
GeorgeGG
I've changed as your instruction, but the status is same:
Cannot show online or offline automatically.
I've checked server with src="ftp://server/teng/online.gif"
Server side feedback is normal:
> logged in anonymously with login/pass : anonymous/IEUser@
> 230 User teresa logged in.
> TYPE I
> 200 Type set to I.
> PASV
> 227 Entering Passive Mode (203,80,102,86,72,198).
> SIZE /teng/online.gif
> 550 No such file or directory.
> RETR /teng/online.gif
> asked to download 'e:\online.gif' --> Access allowed.
> 150 Data connection accepted from 203.80.102.86:1226; transfer starting for online.gif (2673 bytes).
> started downloading 'e:\online.gif'.
> finished downloading 'e:\online.gif' - (00:00:01 - 2.610 KB - 2.610 KBytes/s)
> 226 Transfer ok
> ABOR
> 226 ABOR command successful.
My be something wrong at my side?
Teresa
Then make the results change the innerhtml for a results area. The contents of that area before load could be 'Testing Remote Server'
Hope this is clear, haven't tested the ideas but am pretty sure they would work nicely.