Forum Moderators: coopster

Message Too Old, No Replies

Testing to see if a page is active?

not sure what to use...

         

johnglass

1:07 am on Apr 7, 2004 (gmt 0)

10+ Year Member



Hi,

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

barn_de

9:56 am on Apr 7, 2004 (gmt 0)

10+ Year Member



hi 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

johnglass

4:26 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



Cool thanx barn, I'll give that a shot later tonite and let you know how it goes.

:)

johnglass

johnglass

4:56 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



By the way...

The radio station is in fact on my computer (the computer sitting next to me, actually). The same computer also serves as a workstation and ftp server.

However, my website is on a rented server. Would that affect your solution?

Thanx again,

johnglass

barn_de

9:31 am on Apr 8, 2004 (gmt 0)

10+ Year Member



as long as you know the ip address of your computer it shouldn't be a problem.

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

johnglass

5:09 pm on Apr 9, 2004 (gmt 0)

10+ Year Member



Hi 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

johnglass

5:10 pm on Apr 9, 2004 (gmt 0)

10+ Year Member



er... fsockopen()

:)

johnglass

10:17 am on Apr 20, 2004 (gmt 0)

10+ Year Member



I finally got it working! :)

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

johnglass

10:23 am on Apr 20, 2004 (gmt 0)

10+ Year Member



Oh i see...

The $errno and $errstr detect what's wrong and then return it as a string (the same error messages I'm blocking with the @). Cool. :)