Simple check (PHP) to see if Shoutcast radio is online?
Use fsockopen and check for an error.
$fp = fsockopen("www.example.com", 8000, $errno, $errstr, 1); //last param is timeout in seconds
if (!$fp) {
echo "$errstr ($errno)<br />\n"; // radio offline
} else {
fclose($fp); // radio OK
}
You have to try and figure it out timeout
, but your best bet is to run this with a long timeout in the background of cron, and store the results somewhere.
source to share
Sorki's answer is fine if you just want to determine that the server is up, but as Gumbo pointed out, there are different levels of "online".
For example, the server can be shut down to prevent it from accepting streaming connections. The server can accept streaming connections, but the source can be disconnected.
To do this, you need to check the status in the /7.html file. Get into it with "Mozilla" on the user-agent string. You will end up with something like this:
2,1,22,625,2,128,How Far To Austin - Don't Get Me Wrong
Data field:
listeners, status, peak listeners, maximum listeners, unique listeners, bitrate, track meta
Easy to disassemble ... just blow () on it.
source to share
If this is your radio (you know the password and username), you can use CURL. Try to get the value of $ xml-> STREAMSTATUS from this piece of code:
<?php
$useragent = "Mozilla (DNAS 2 Statuscheck)";
$sc_host = '192.168.0.1';
$sc_port = '8000';
$sc_user = 'admin';
$sc_pass = 'XXXXX';
$sc_sid = '1';
$ch = curl_init($sc_host . '/admin.cgi?mode=viewxml&sid=$sc_sid');
curl_setopt($ch, CURLOPT_PORT, $sc_port);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $sc_user . ':' . $sc_pass);
$curl = curl_exec($ch);
if ($curl)
{
$xml = simplexml_load_string($curl);
// THIS IS THE ANSWER FOR YOUR QUESTION:
var_dump($xml->STREAMSTATUS);
// if retuns 1 - radio is online
// if retuns 0 - radio is offline
}
else
{
die('Could not connect to dnas-server!');
}
?>
enjoy
source to share