Display server status (on or off) On web page
Curious. I am starting to stream online high school soccer games online and he uses a program to stream feeds from my computer. However, when I close the program or computer down, the server shuts down and guests cannot access the channels.
Is there any code I can post on my website that will show my guests if the server is up? I would think it would be a simple code, php script, or something that periodically checks if the site is online and then shows ON or OFF.
a source to share
EDIT: use @fsockopen
or you will get a warning Cannot connect to the server
that you can ignore, as this is what you are actually trying to test.
$ping = @fsockopen('myURL or IP', 80, $errno, $errstr, 10);
if (!$ping) // site is down
eg:
<?php
$URL = 'randomurlfortestingpurposes.com';
$ping = @fsockopen ($URL, 80, $errno, $errstr, 10);
(!$ping) ? $status = $URL.' is down' : $status = $URL.' is up';
echo $status.'<br>';
$URL = 'google.com';
$ping = @fsockopen ($URL, 80, $errno, $errstr, 10);
(!$ping) ? $status = $URL.' is down' : $status = $URL.' is up';
echo $status;
?>
Outputs
randomurlfortestingpurposes.com is down
google.com is up
a source to share
There are two options here: first, you can request a response from the remote server, and if it doesn't exist (after some timeout), claim it is disabled. You can cache this if the response time might be slower than the time users want to wait, or drag and drop it into an AJAX request, which can then remove the video player, display a notification, etc. On failure.
Another alternative is to check for a feed failure and display an offline server message.
a source to share