Helpful Information
 
 
Category: Other
Script to detect website status

Hello all,

I am looking for a script to detect the presence of a website (my home server), and to display text depending on whether the site is accessible or not.

The site is www.serberus.r8.org (Serberus is the network name of my system), that site will redirect to a longer url - it's a forwarder. You will probably get a page not found error as my server is usually off.

Because the server is rarely on, I need the script to check if it's online and write a link to the server if it is.

For example:
Server is online: Script writes "Serberus Online"
Server is offline: Script writes "Serberus Unavaliable"

If you have any questions at all, please feel free to ask as this script is highly desired.

Regards
cr3ative

edit: My 888th post :)

I am looking for a script to detect the presence of a website (my home server), and to display text depending on whether the site is accessible or not.With which language in particular? It should be possible with any decent server-side language and it's possible client-side, too (though only with certain browsers).

Mike

The page which displays the text can't be on my server, so I would have to use my personal ISP space, and I'm not sure if they support many server-side technologies.

In an ideal situation, it would be made with javascript, but I'm sure I can ask my ISP to install a server-side application or two.

It's also worth noting that when it comes to server-side, I'm useless. I can tinker with .htaccess and mod.rewrite, but that's about it.

Thanks for your time
cr3ative

[...] it's possible client-side, tooUnfortunately, I was mistaken there. Whilst the XMLHttpRequest object can be used in some user agents to make HTTP requests to a remote server, there are security restrictions which mean requests can only go to the originating server for the current document.

So, you're back to only having a server-side option (well, unless you want to write - and sign[!] - a small Java applet). It can certainly be done with PHP (I'm looking for the best way, at the moment).

Mike

Thank you very much for your time on this matter. I look forward to your findings.

I can also PM you my FTP access details if need be to set this up, as I am useless with PHP.

edit: My ISP space supports the following: Perl & SSI, PHP Version 4.1.2

Cheers
cr3ative

A basic implementation would be


<?php
$host = 'your domain name';
if($socket = fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'The content you want to insert';
fclose($socket);
}
?>This simply attempts to connect to the address (name or IP) identified in host. If the connection succeeds, a string will be written into the location of the code. I take it that the IP address of your server is static?

The host name should be just a name: don't add a scheme (i.e. http://).

The last argument in the fsockopen call is the timeout before the connection aborts. You'll probably want lower than 30 (otherwise users might be waiting for thirty seconds before they get a complete response from your server), but don't make it too low otherwise you'll get a false-positive if network traffic is high. In my brief tests, my local Web server automatically cut out before the timeout (at around twenty two seconds) so you can't specify an excessive timeout period anyway.

I don't guarantee that this will work: though I didn't find any security restrictions mentioned, there might be some of which I'm not aware.

Mike

edit: It works in my preliminary testing. Now to try to go live...

cr3ative

Excellent!



<?php
$host = 'i-83-67-3-25.freedom2surf.net';
if($socket = fsockopen($host, 404, $errno, $errstr, 30)) {
echo 'Serberus is online!';
fclose($socket);
} else {
echo 'Serberus appears to be offline.';
}
?>

This example works, I've uploaded it at www.gerryhyh.f2s.com/paul/serberus.php - the only changes I had to make were to change the port to 404 (which serberus uses).

Thanks very much! :)
cr3ative

Thanks very much! :)You're welcome. :D

Mike










privacy (GDPR)