Custom PHP Radio

Hey,

We use a custom made radio on our forum and have tweakwed it to work as a addon application to IPB (Invision Power Board 3.1.x) the script works great for us HOWEVER! my host has suspended us and told us we must move to a VPS as we are using too much CPU we only have 180 members and host says we are useing 200% CPU >:( do it must be our script thats causing the issue here is the PHP script that powers the radio;

<?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 = "

{$this->lang->words[ {$this->lang->words['shoutcast_important_warning']}

No Connection: Failed to connect through fsockopen ($errstr $errno) to the SHOUTcast server.

"; 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 = "

{$this->lang->words[ {$this->lang->words['shoutcast_important_warning']}

Bad login: Please check your connection details make sure they are correct, passwords are (CaSe SeNsItIvE).

"; return false; } $xmlparser = xml_parser_create(); if (!xml_parse_into_struct($xmlparser, $this->xml, $this->values, $this->indexes)) { $this->error = "

{$this->lang->words[ {$this->lang->words['shoutcast_important_warning']}

Unparsable XML: Please reset xml stats in your SHOUTcast server administrator control panel Click Here.

"; 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;$iindexes['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;$iindexes['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; } } } Could that be using up all the CPU? if so how can we tweek it for better performance! i thank you for taking the time to help us out! if u want a copy of the full script we have it avalible to download on our forum http://www.lovewarez.co.uk/forum/index.php
Sponsor our Newsletter | Privacy Policy | Terms of Service