Jump to content

Help: fsockopen()


clown[NOR]

Recommended Posts

I found this script online. Using it to read info about my radio stations.. but something is not working as it should... when I test it trough wamp5 it works perfectly giving me the stats, but when I upload it it sais that the servers are down... the code I'm using is this:


<?php
/*

Live SHOUTcast statistics for multiple servers

This script is (C) Gavin Bell 2006

If you use this script, please leave the copyright notice and link at the bottom of the page or link to www.bellonline.co.uk somewhere on your website. Feel free to modify it in any other way to suit your needs.

Version: v1.0

http://www.bellonline.co.uk/


*/
/* ---------- General configuration ---------- */

$station_name = "Strictly Underground";

$refresh = "60";  // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline

/* ----------- Server configuration ---------- */

// Note: dont include http://
// Main server: The song title will be taken from this server

$ip[1] = "208.109.236.118"; 
$port[1] = "42874";
$url[1] = "http://strictlyunderground.listen2myradio.com/";

/* Relays: Below you can enter more relays / restreams / channels / competitors or anything else */

$ip[2] = "208.109.236.118";
$port[2] = "42890";
$url[2] = "http://undergrunn.listen2myradio.com/";

/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$servers = count($ip);
?>
<?php
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$i],$errno,$errstr,$timeout);
if (!$fp) 
	{ 
	$listeners[$i] = "0";
	$msg[$i] = "<span class=\"red\">ERROR [Connection refused ($ip[$i]) / Server down]</span>";
	$error[$i] = "1";
	} 
else
	{ 
	fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
	while (!feof($fp)) 
		{
		$info = fgets($fp);
		}
	$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
	$info = str_replace('</body></html>', "", $info);
	$stats = explode(',', $info);
	if (empty($stats[1]) )
		{
		$listeners[$i] = "0";
		$msg[$i] = "<span class=\"red\">ERROR [There is no source connected ($ip[$i])]</span>";
		$error[$i] = "1";
		}
	else
		{
		if ($stats[1] == "1")
			{
			$song[$i] = $stats[6];
			$listeners[$i] = $stats[0];
			$max[$i] =  $stats[3];
			$bitrate[$i] = $stats[5];
			$peak[$i] = $stats[2];
			if ($stats[0] == $max[$i]) 
				{ 
				$msg[$i] .= "<span class=\"red\">";
				}
			$msg[$i] .= "Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners";
			if ($stats[0] == $max[$i]) 
				{ 
				$msg[$i] .= "</span>";
				}
			$msg[$i] .= "\n    <p><b>Listener peak:</b> $peak[$i]";
			}
		else
			{
			$listeners[$i] = "0";
			$msg[$i] = "    <span class=\"red\">ERROR [Cannot get info from server ($ip[$i])]</span>";
			$error[$i] = "1";
			}
		}
	}
$i++;
}
$total_listeners = array_sum($listeners) ;
print "<div id=\"blu\">\n  <div style=\"text-align: center;\">\n    <strong>There are $total_listeners listeners locked</strong>\n  </div>\n</div>\n<div>\n  <div>\n    <p><b>Current song:</b> $song[1]</p>\n  </div>\n</div>\n<div><hr />\n";
$i = "1";
while($i<=$servers)
{
  	  print "  <div>\n";
if ($max[$i] > 0) 
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] != "1") 
{
?>
    <table width="400"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="25%" align="center"><b><a href="<?php echo $url[$i]; ?>" target="_blank">Server <?php print "#".$i ?></a></b>  </td>
        <td width="75%" colspan="3" bgcolor="#eeeeee"><img src="<?php if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<?php print $barlength ?>" height="12" alt="The server is at <?php print $percentage; ?>% capacity"></td>
      </tr>
      <tr>
        <td width="25%"> </td>
        <td width="25%">0%</td>
        <td width="25%" align="center">50%</td>
        <td width="25%" align="right">100%</td>
      </tr>
    </table>
<?php
}
else
{
?>
    <table width="400"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="25%" align="center"><b><a href="<?php echo $url[$i]; ?>" target="_blank">Server <?php echo "#".$i ?></a></b>  </td>
        <td width="75%" colspan="3" bgcolor="#eeeeee"> </td>
      </tr>
      <tr>
        <td width="25%"> </td>
        <td width="25%">0%</td>
        <td width="25%" align="center">50%</td>
        <td width="25%" align="right">100%</td>
      </tr>
    </table>
<?php
}
print "    <p><b>Status:</b> $msg[$i]</p>\n  </div>\n  <div class=\"line\"> </div><hr />\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("H:i:s", time() + $time_difference);
$date = date("l, F jS, Y", time() + 0);
print "<div>\n  <div>\n    <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n  </div>\n</div>\n";
?>


 

Thanks In Advance

- Clown

Link to comment
Share on other sites

that $url part was a modification I used to make it work with my radio... the thing you commented here is based on the $ip[]... and as you can see... I did not add http://... if I did something that shouldn't make the script stop working, then it shouldn't work on my computer trough wamp5... or?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.