my host says this script is using 200% CPU and has made us move to a VPS. would this script use too much CPU if so would it be possible to limit how much it is using? thank in advance!
[php]<?php
if ( ! defined( ‘IN_IPB’ ) )
{
print “
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.”;exit();
}
class SHOUTcastXML
{
var $xml;
var $host;
var $port;
var $pass;
var $error;
var $seconds;
public function __construct( $registry )
{
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->lang = $this->registry->getClass('class_localization');
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
$this->cache = $this->registry->cache();
$this->caches =& $this->registry->cache()->fetchCaches();
}
function OpenStats()
{
$fp = @fsockopen($this->host, $this->port, $errno, $errstr, 1);
if (!$fp) {
$this->error = "<div class='warning'>
<h4><img src='{$this->settings['skin_acp_url']}/_newimages/icons/bullet_error.png' border='0' alt='{$this->lang->words['cp_error']}' /> {$this->lang->words['shoutcast_important_warning']}</h4>
<b>No Connection: Failed to connect through fsockopen ($errstr $errno) to the SHOUTcast server.</b>
</div><br />";
return false;
} else {
fputs($fp, "GET /admin.cgi?pass=".$this->pass."&mode=viewxml HTTP/1.0\r\n");
fputs($fp, "User-Agent: Mozilla\r\n\r\n");
while (!feof($fp)) {
$this->xml .= fgets($fp, 128);
}
fclose($fp);
if (stristr($this->xml, "HTTP/1.0 200 OK") == true) {
$this->xml = trim(substr($this->xml, 42));
} else {
$this->error = "<div class='warning'>
<h4><img src='{$this->settings['skin_acp_url']}/_newimages/icons/bullet_error.png' border='0' alt='{$this->lang->words['cp_error']}' /> {$this->lang->words['shoutcast_important_warning']}</h4>
<b>Bad login: Please check your connection details make sure they are correct, passwords are (CaSe SeNsItIvE).</b>
</div><br />";
return false;
}
$xmlparser = xml_parser_create();
if (!xml_parse_into_struct($xmlparser, $this->xml, $this->values, $this->indexes)) {
$this->error = "<div class='warning'>
<h4><img src='{$this->settings['skin_acp_url']}/_newimages/icons/bullet_error.png' border='0' alt='{$this->lang->words['cp_error']}' /> {$this->lang->words['shoutcast_important_warning']}</h4>
<b>Unparsable XML: Please reset xml stats in your SHOUTcast server administrator control panel <a href='http://$this->host:$this->port/admin.cgi?mode=resetxml' target='_blank'>Click Here</a>.</b>
</div><br />";
return false;
}
xml_parser_free($xmlparser);
return true;
}
}
function GetCurrentListenersCount()
{
return($this->values[$this->indexes["CURRENTLISTENERS"][0]]["value"]);
}
function GetPeakListenersCount()
{
return($this->values[$this->indexes["PEAKLISTENERS"][0]]["value"]);
}
function GetMaxListenersCount()
{
return($this->values[$this->indexes["MAXLISTENERS"][0]]["value"]);
}
function GetReportedListenersCount()
{
return($this->values[$this->indexes["REPORTEDLISTENERS"][0]]["value"]);
}
function GetAverageListenTime()
{
return($this->values[$this->indexes["AVERAGETIME"][0]]["value"]);
}
function GetServerGenre()
{
return($this->values[$this->indexes["SERVERGENRE"][0]]["value"]);
}
function GetServerURL()
{
return($this->values[$this->indexes["SERVERURL"][0]]["value"]);
}
function GetServerTitle()
{
return($this->values[$this->indexes["SERVERTITLE"][0]]["value"]);
}
function GetCurrentSongTitle()
{
return($this->values[$this->indexes["SONGTITLE"][0]]["value"]);
}
function GetIRC()
{
return($this->values[$this->indexes["IRC"][0]]["value"]);
}
function GetAIM()
{
return($this->values[$this->indexes["AIM"][0]]["value"]);
}
function GetICQ()
{
return($this->values[$this->indexes["ICQ"][0]]["value"]);
}
function GetWebHitsCount()
{
return($this->values[$this->indexes["WEBHITS"][0]]["value"]);
}
function GetStreamHitsCount()
{
return($this->values[$this->indexes["STREAMHITS"][0]]["value"]);
}
function GetStreamStatus()
{
return($this->values[$this->indexes["STREAMSTATUS"][0]]["value"]);
}
function GetBitRate()
{
return($this->values[$this->indexes["BITRATE"][0]]["value"]);
}
function GetSongHistory()
{
for($i=1;$i<sizeof($this->indexes['TITLE']);$i++) {
$history[$i-1] = array(
"playedat"=>$this->values[$this->indexes['PLAYEDAT'][$i]]['value'],
"title"=>$this->values[$this->indexes['TITLE'][$i]]['value']
);
}
return($history);
}
function GetListeners()
{
for($i=0;$i<sizeof($this->indexes['USERAGENT']);$i++) {
$listeners[$i] = array(
"hostname"=>$this->values[$this->indexes['HOSTNAME'][$i]]['value'],
"useragent"=>$this->values[$this->indexes['USERAGENT'][$i]]['value'],
"underruns"=>$this->values[$this->indexes['UNDERRUNS'][$i]]['value'],
"connecttime"=>$this->values[$this->indexes['CONNECTTIME'][$i]]['value'],
"pointer"=>$this->values[$this->indexes['POINTER'][$i]]['value'],
"uid"=>$this->values[$this->indexes['UID'][$i]]['value'],
);
}
return($listeners);
}
function ConvertSeconds()
{
$tmpseconds = substr( "00".$this->seconds % 60, -2 );
if ( $this->seconds > 59 ) {
if ( $this->seconds > 3599 ) {
$tmphours = substr( "0".intval( $this->seconds / 3600 ), -2 );
$tmpminutes = substr( "0".intval( $this->seconds / 60 - ( 60 * $tmphours ) ), -2 );
return ( $tmphours.":".$tmpminutes.":".$tmpseconds );
} else {
return ( "00:".substr( "0".intval( $this->seconds / 60 ), -2 ).":".$tmpseconds );
}
} else {
return ( "00:00:".$tmpseconds );
}
}
function GetErrorReport()
{
return($this->error);
}
function GetStats()
{
$stats = array();
$this->host = $this->settings['shoutcast_host'];
$this->port = $this->settings['shoutcast_port'];
$this->pass = $this->settings['shoutcast_pass'];
if ($this->OpenStats()) {
if ($this->GetStreamStatus())
{
$stats['CURRENTLISTENERS'] = $this->GetCurrentListenersCount();
$stats['PEAKLISTENERS'] = $this->GetPeakListenersCount();
$stats['MAXLISTENERS'] = $this->GetMaxListenersCount();
$stats['REPORTEDLISTENERS'] = $this->GetReportedListenersCount();
$stats['AVERAGETIME'] = $this->GetAverageListenTime();
$stats['SERVERGENRE'] = $this->GetServerGenre();
$stats['SERVERURL'] = $this->GetServerURL();
$stats['SERVERTITLE'] = $this->GetServerTitle();
$stats['SONGTITLE'] = $this->GetCurrentSongTitle();
$stats['IRC'] = $this->GetIRC();
$stats['AIM'] = $this->GetAIM();
$stats['ICQ'] = $this->GetICQ();
$stats['WEBHITS'] = $this->GetWebHitsCount();
$stats['STREAMHITS'] = $this->GetStreamHitsCount();
$stats['STREAMSTATUS'] = $this->GetStreamStatus();
$stats['BITRATE'] = $this->GetBitRate();
return $stats;
}
else
{
$stats['STREAMSTATUS'] = '0';
$stats['WEBHITS'] = $this->GetWebHitsCount();
$stats['STREAMHITS'] = $this->GetStreamHitsCount();
$stats['REPORTEDLISTENERS'] = $this->GetReportedListenersCount();
$stats['AVERAGETIME'] = $this->ConvertSeconds($this->GetAverageListenTime());
return $stats;
}
}
else
{
$stats['STREAMSTATUS'] = 'error';
$stats['ERROR'] = $this->GetErrorReport();
$stats['WEBHITS'] = "Warning: Unable to connect";
$stats['STREAMHITS'] = "Warning: Unable to connect";
$stats['REPORTEDLISTENERS'] = "Warning: Unable to connect";
$stats['AVERAGETIME'] = "Warning: Unable to connect";
return $stats;
}
}
}[/php]