views:

486

answers:

1

Basically, just a simple script that can check to see if a shoutcast radio is online or not, and output a code based on it.

I tried to do this with file_get_contents and eregi, but it didn't seem to work, or was waaaaay to slow.

Cheers.

:)

A: 

Use fsockopen and check for the 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 determine the timeout but it might be best to run this with bigger timeout regularly on background with cron and saving the results somewhere.

sorki