|
Posted by dirk van lierop on 09/28/01 11:57
Hello All,
I'm making a online web radio wich will auto refresh its song title and
users. and what i want to do is to auto refresh an echo so when song changes
it will change without refreshing the whole webpage.
how can i do this? so just the echo of server status, stream status,
listener peak and current song need to get auto updated.
Thanks in advance,
Dirk van Lierop d.vanlierop1@chello.nl
///////////////////////////////////////////////////////////////////////////////////////////
Here is my code:
<?php
$config["host"] = "*****myip****";
$config["port"] = "*****myport****";
$strShoutCastResult = null;
$blnServerStatus = false;
$arrServerStatus = Array();
function _DownloadFile()
{
global $config;
$tmpStr = null;
$fSock = @fsockopen($config["host"], $config["port"], $errno, $errstr,
5); /* Open Connection, Timeout 5 Seconds */
if (!$fSock)
{
return false;
}
else
{
@fwrite($fSock,
"GET /7.html HTTP/1.0\r\n" .
"User-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"
);
while(!feof($fSock))
{
$tmpStr .= fgets($fSock, 1024);
}
}
@fclose($fSock);
return $tmpStr;
}
$strShoutCastResult = _DownloadFile();
if(stristr($strShoutCastResult, "HTTP/1.0 200 OK") === FALSE)
{
$blnServerStatus = false;
}
else
{
$blnServerStatus = true;
preg_match("/(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(.*)/",
$strShoutCastResult, $arrServerStatus);
array_shift($arrServerStatus);
}
/*
[0] = Current Listeners
[1] = Connected?
[2] = Peak Listeners
[3] = Max Listeners
[4] = Reported Listeners
[5] = kbps (Steam Rate)
[6] = Song Playing
Why is [0] Exactly The Same As [4] ? - We ll Just Use 4...
*/
if ($blnServerStatus)
{
if ($arrServerStatus["1"] == "1")
{
echo "<b>Server Status:</b> Server is currently up and public.
<br />";
echo "<b>Stream Status:</b> Stream is up at ".
$arrServerStatus["5"] ." kbps with ". $arrServerStatus["4"] ." of ".
$arrServerStatus["3"] ." listeners. <br />";
echo "<b>Listener Peak:</b> ". $arrServerStatus["2"] ." <br />";
echo "<b>Current Song:</b> ". $arrServerStatus["6"] ."<br />";
}
else
{
echo "<b>Server Status:</b> Server is currently down.<br /><br
/>";
}
}
else
{
echo "Server Is Offline! - Unable To Fetch Data/ParseData.";
}
// echo "<br /><br /><hr />". highlight_file(__FILE__, true);
?>
Navigation:
[Reply to this message]
|