Forum Moderators: coopster
I have a Shoutcast station that is on and off pretty regularly. I'd like to make a "power light" on my website to detect whether the station is on or off.
I'm not quite sure what the best language to handle this would be, but I think PHP should be able to do it...
The station is basically outputted as a link, like this:
[myurl.com:8000...]
If it's on, it pops open the app and goes to town.. If it's off, it gives a "page cannot be displayed error" (I'd like to do something about that, but that's a different story).
So basically, I want to query the link, and if it comes back active (or true or 1 or whatever), then it includes a certain graphic; if it's not active (or false or 0 etc.) then it'd include another. I'm thinking it'd be use simple if/else statement, something like this:
$radiostatus = *radiostationquery*
if ($radiostatus == true) {
echo "poweron.gif";
} else {
echo "poweroff.gif";
}
But I'm not sure what *radiosationquery* would be. Seems like it'd be a pretty simple command. Someone (familiar with coding, but not php) suggested the Get() command might be a way to do it.
So, anyone know how to do this? :)
Thanx, johnglass
i don't know a solution to check if the radiostation is on or off. but if it depends on your computer to be on or off, you can just do a ping to your domain.
ob_start();
system('ping -c 1 mydomain.com', $iExit);
ob_end_clean();
whereas $iExit returns you if the ping was successful or not.
0 = successful
1 = failed
barn
so does this mean, that the shoutcast service is available as long as your computer is connected to the internet or do you sometimes turn off the shoutcast service on your home computer and still be connected to the internet?
the ping solution works only, if it can't ping your computer.
barn
Well, the Shoutcast station only available when I have it running. I try and keep it running all the time, turning it off when I play a connection-intensive game or, it crashes :) Both are reasons I'd like the automatic power light on my site.
I have two computers, connected through a router to the same cable internet (the station is local), while the webpage resides on a rented server.
Here's something interesting that I found at Shoutcasts' forums, a signature script written by someone named DJ Killer (hope I'm not breaking any rules by linking this).
[lunchbreak.net...]
I was looking at that and was thinking I could somehow adapt that to serve what I need. It looks to me like he's using the fopen() command to connect to the station.
Gonna keep plowing at it, but your thoughts would be appreciated Barn :)
Thank you for your help,
johnglass
Here's what I used if anyone's curious:
<?php
$radiocheck = @fsockopen("www.mysite.com", 8000, $errno, $errstr, 1);
if(!$radiocheck) {
echo "no";
}
else {
echo "yes";
}
@fclose($radiocheck);
?>
In regards to fsockopen, "www.mysite.com" can also be an ip (I have mine dynamically routed), 8000 is the port (default for Shoutcast), $errno and $errstr are some kind of global error checking variables (not sure precisely what they do - whatever, they work, i'll find out why later), and 1 is the time allowed for checking the status (it only needs one second in this case). Add @ to prevent error messages from being returned (only the "no"). And of course you can replace "yes" and "no" with whatever you want (like a power light graphic :) ).
Works great and can be used for alot of things (fsockopen is a powerful command and can do alot more than the simple thing i'm using it for here).
Hope that helps someone as much as it helped me. :)
L8s - johnglass