Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Reply
Thread Tools Search this Thread Display Modes
Old 6th October 2010, 14:04   #1
Guldstrand
Junior Member
 
Join Date: Jun 2006
Location: Sweden
Posts: 17
Question about "Current song"

I´m trying to show a custom message when there isn´t any current song (server is down), but it doesn´t seem to work.

Here is the code:

PHP Code:
<?php 

error_reporting
(E_ALL);
ini_set("display_errors""1"); 

$open fsockopen("MYIP","12345"); 
if (
$open) { 
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n"); 
$read fread($open,1000); 
$text explode("content-type:text/html",$read); 
$text explode(",",$text***91;1***93;); 
} else { 
$er="Anslutningen nekades!"; } 

if (
$text***91;1***93;==1) { $state "Up"; } else { $state "Down"; } 
if (
$er) { echo $er; exit; } 

if (
$text***91;6***93; !== "") { 
$song $text***91;6***93;; 
} else { 
$song "servern är offline"
}

echo 
"Current Song: $song";
?>
It only shows
Quote:
Current Song:
..when the server is down.
Guldstrand is offline   Reply With Quote
Old 6th October 2010, 16:52   #2
thinktink
Forum King
 
thinktink's Avatar
 
Join Date: May 2009
Location: Somewhere on this planet.
Posts: 2,182
Send a message via Skype™ to thinktink
I did some tests. The 7th element (the song name, index 6) doesn't go blank when the source is disconnected. You have to use the status from the 2nd element (server status, index 1) to determine that. I have updated the code below:

PHP Code:
<?php 

error_reporting
(E_ALL);
ini_set("display_errors""1"); 

$open fsockopen("MYIP","12345"); 
if (
$open) { 
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n"); 
$read fread($open,1000); 
$text explode("content-type:text/html",$read); 
$text explode(",",$text***91;1***93;); 
} else { 
$er="Anslutningen nekades!"; } 

if (
$text***91;1***93;==1) { $state "Up"; } else { $state "Down"; } 
if (
$er) { echo $er; exit; } 

if (
$text***91;1***93;== 1) { 
$song $text***91;6***93;; 
} else { 
$song "servern är offline"
}

echo 
"Current Song: $song";
?>
[EDIT/]
Oops, recheck the code, inversed the logic on the server status test by mistake.

You probably should drop 7.html though and focus on grabbing the stats from the xml data instead. The new DNAS2 does not have 7.html
thinktink is offline   Reply With Quote
Old 6th October 2010, 17:18   #3
Guldstrand
Junior Member
 
Join Date: Jun 2006
Location: Sweden
Posts: 17
The page loads for a long time, before it says "Anslutningen nekades!". (Connection refused).
Is there a way to optimize/speed up this?
Guldstrand is offline   Reply With Quote
Old 6th October 2010, 17:50   #4
thinktink
Forum King
 
thinktink's Avatar
 
Join Date: May 2009
Location: Somewhere on this planet.
Posts: 2,182
Send a message via Skype™ to thinktink
Quote:
Originally Posted by Guldstrand View Post
The page loads for a long time, before it says "Anslutningen nekades!". (Connection refused).
Is there a way to optimize/speed up this?
http://php.net/manual/en/function.fsockopen.php
http://www.php.net/manual/en/functio...et-timeout.php

PHP Code:
<?php
$errno
=0;$errstr="";$ssto=1;

error_reporting(E_ALL);
ini_set("display_errors""1");
$er="";
$text="";
$state="";
$read="";
$open = @fsockopen("MYIP","12345",$errno,$errstr,$ssto);
if (
$open) {
@
stream_set_timeout($open,$ssto);
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
$read fread($open,1000);
@
fclose($open);
$text explode("content-type:text/html",$read);
$text explode(",",$text***91;1***93;);

if (
$text***91;1***93;==1) { $state "Up"; } else { $state "Down"; }
if (
$text***91;1***93;== 1) {
$song $text***91;6***93;;
} else {
$song "servern är offline";
}

} else { 
$er="Anslutningen nekades!"; }

if (
$er) { echo $er; exit; }


echo 
"Current Song: $song";
?>

Last edited by thinktink; 6th October 2010 at 18:37. Reason: Tested on live server, re-edited to satisfy warnings.
thinktink is offline   Reply With Quote
Old 6th October 2010, 21:16   #5
Guldstrand
Junior Member
 
Join Date: Jun 2006
Location: Sweden
Posts: 17
That worked beautifully.
Thanks mate...
Guldstrand is offline   Reply With Quote
Old 7th October 2010, 00:26   #6
thinktink
Forum King
 
thinktink's Avatar
 
Join Date: May 2009
Location: Somewhere on this planet.
Posts: 2,182
Send a message via Skype™ to thinktink
You're welcome.
thinktink is offline   Reply With Quote
Reply
Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump