PDA

View Full Version : offline status without DNAS server


ukraina
6th March 2004, 21:36
Is it possible to get a offline status in my website when the dnas server is kill, shutdown?


I have allready a php script at my website and tell to visiters if we are online with music and allso what's playing at the moment, when I am not streaming (no source) then allso this script tell that the webradio is offline as long the dnas server is there in the internet.
I have 2 servers.


Somebody know what i must change in this script when server is complete shutdown? I want if server is shutdown in my website get the message that the radio is offline and not a picture what not can show

here is the php script what's only works when the dnas server is there.

<?php
// This image you can call immediately from an html file in the image tag
// (i.e. <image src="black.php"> ) easy huh?

Header("Content-type: image/png");

// Fill in your own server information here:
$host = "81.171.103.188";
$port = "9440";
$listenlink = 'http://81.171.103.188:9440/listen.pls'; //make link to stream

$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection
if(!$fp) {
$success=2; //se-t if no connection
}
if($success!=2){ //if connection
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp); //close connection
$page = ereg_replace(".*<body>", "", $page); //extract data
$page = ereg_replace("</body>.*", ",", $page); //extract data
$numbers = explode(",",$page); //extract data
$currentlisteners=$numbers[0]; //set variable
$connected=$numbers[1]; //set variable

if($connected==1) //if DSP is connected
$wordconnected="yes"; //set variable
else //if no DSP connection
$wordconnected="no"; //set variable
$peaklisteners=$numbers[2]; //set variable
$maxlisteners=$numbers[3]; //set variable
$reportedlisteners=$numbers[4]; //set variable
$bit=$numbers[5];
}

// Image size can be changed here: (x, y)
$im = ImageCreate(200,60);

// Background color in R(ed)G(reen)B(lue) below
$background_color = ImageColorAllocate($im,0,0,0);

// text colors also in RGB
$text_color1 = ImageColorAllocate($im,0,204,255);
$text_color2 = ImageColorAllocate($im,0,204,51);

if($success!=2 && $connected==1){

// song information is splitted in artist - title:
// This requires consistent artist & title format (no ' - ' in title/artist)
// else you can use $numbers[6] as current song info below
$song=explode(" - ",$numbers[6]);

// strings can of course be replaced with your own bla
$string1= "Now playing on Liberty Radio";
$string2= $song[0];
$string3= $song[1];
$string4= "SERVER1: $bit kbps [$currentlisteners/$maxlisteners users]";
}
else {
$string1= "Liberty Radio is currently";
$string2= "OFFLINE.";
$string3= "Please return later.";
$string4= "SERVER1";
}

// positioning below
$px = (imagesx($im)-5*strlen($string1))/2;
ImageString($im,1,$px,5,$string1,$text_color1);
// (image,font (from 1 to 5),starting x position, y position,line of text,color)
$px = (imagesx($im)-5*strlen($string2))/2;
ImageString($im,1,$px,20,$string2,$text_color2);
$px = (imagesx($im)-5*strlen($string3))/2;
ImageString($im,1,$px,30,$string3,$text_color2);
$px = (imagesx($im)-5*strlen($string4))/2;
ImageString($im,1,$px,45,$string4,$text_color1);
ImagePng($im);
// In response to KXRM's reaction:
// if you want to cache the picture, you should place this script in
// your internetpage, remove line 5 (Header-call)
// and use ImagePng($im, "filename.png");
// NB: filename.png must have the right permission settings
// (CHMOD 777 does it)
//
// Then you can place filename.png in the same html-file.
ImageDestroy($im);
?>

djmastermind
7th March 2004, 04:49
I don't know a damn thing about PHP, but here (http://forums.winamp.com/showthread.php?s=&threadid=172373)'s a recently posted script that you can comb through. I believe that this can be done with an "else" statement.

FesterHead
7th March 2004, 06:59
Please don't doublepost.

Discussion continued here (http://forums.winamp.com/showthread.php?s=&threadid=172175).