PHP-第页上正在更新Icecast信息

PHP-第页上正在更新Icecast信息,php,icecast,Php,Icecast,我正在使用一个来自网站的脚本。这个脚本对我来说很好,它做了它需要做的事情,但我有一个问题。当曲目在我的Icecast服务器上完成时,它不会在站点上获得更新。因此,如果我的歌曲是“偷了节目”,那么它会在页面上显示“偷了节目”,但当歌曲完成后,例如“大声思考”开始时,页面仍会在刷新时显示“偷了节目”,它会更新。但是如何使页面自动更新,用户不必手动刷新 PHP <?php // include the class file include( 'icecast.php' );

我正在使用一个来自网站的脚本。这个脚本对我来说很好,它做了它需要做的事情,但我有一个问题。当曲目在我的Icecast服务器上完成时,它不会在站点上获得更新。因此,如果我的歌曲是“偷了节目”,那么它会在页面上显示“偷了节目”,但当歌曲完成后,例如“大声思考”开始时,页面仍会在刷新时显示“偷了节目”,它会更新。但是如何使页面自动更新,用户不必手动刷新

PHP

<?php
    // include the class file
    include( 'icecast.php' );

    // instantiate class
    $stream = new IceCast();

    // set server and mount
    $server = 'http://radio.finioxfm.com:8000';
    $file   = '/status.xsl';

    // set the url
    $stream->setUrl($server,$file);

    // get status info
    $radio = $stream->getStatus();

    // assign array to variables
    extract($radio);

    // echo the status
    echo $status.'<br/>';

    // display more stats if ON AIR
    if ($status=='ON AIR') :
    echo $listeners.' listeners<br/>';
    echo $title.'<br/>';
    echo $genre.'<br/>';
    for ($i=0; $i < 1; $i++) { 
        echo $now_playing['artist'].'<br/>';
        echo $now_playing['track'].'<br/>';
    }
    endif;
?>

icecast.php脚本

<?php
class IceCast {
var $server = "http://radio.finioxfm.com:8000";
var $stats_file = "/status.xsl";
var $radio_info=array();

function __construct() {
    // build array to store our Icecast stats   
    $this->radio_info['server'] = $this->server;
    $this->radio_info['title'] = '';
    $this->radio_info['description'] = '';
    $this->radio_info['content_type'] = '';
    $this->radio_info['mount_start'] = '';
    $this->radio_info['bit_rate'] = '';
    $this->radio_info['listeners'] = '';
    $this->radio_info['most_listeners'] = '';
    $this->radio_info['genre'] = '';
    $this->radio_info['url'] = '';
    $this->radio_info['now_playing'] = array();
    $this->radio_info['now_playing']['artist'] = 'Unknown';
    $this->radio_info['now_playing']['track'] = 'Unknown';
    $this->radio_info['status'] = 'OFF AIR';
}

function setUrl($url,$file) {
    $this->server=$url;
    $this->stats_file=$file;
    $this->radio_info['server'] = $this->server;
}

private function fetch() {
    // create a new curl resource
    $ch = curl_init();

    // set the url
    curl_setopt($ch,CURLOPT_URL,$this->server.$this->stats_file);

    // return as a string
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

    // $output = the status.xsl file
    $output = curl_exec($ch);

    // close curl resource to free up system resources
    curl_close($ch);

    return $output;
}

function getStatus() {
    $output=$this->fetch();

    // loop through $output and sort arrays
    $temp_array = array();

    $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
    $search_td = array('<td class="streamdata">','</td>');

    if(preg_match_all("/$search_for/siU",$output,$matches)) {
       foreach($matches[0] as $match) {
          $to_push = str_replace($search_td,'',$match);
          $to_push = trim($to_push);
          array_push($temp_array,$to_push);
       }
    }

    if(count($temp_array)) {
        //sort our temp array into our ral array
        $this->radio_info['title'] = $temp_array[0];
        $this->radio_info['description'] = $temp_array[1];
        $this->radio_info['content_type'] = $temp_array[2];
        $this->radio_info['mount_start'] = $temp_array[3];
        $this->radio_info['bit_rate'] = $temp_array[4];
        $this->radio_info['listeners'] = $temp_array[5];
        $this->radio_info['most_listeners'] = $temp_array[6];
        $this->radio_info['genre'] = $temp_array[7];
        $this->radio_info['url'] = $temp_array[8];

        if(isset($temp_array[9])) {
            $x = explode(" - ",$temp_array[9]);
            $this->radio_info['now_playing']['artist'] = $x[0];
            $this->radio_info['now_playing']['track'] = $x[1];
        }
        $this->radio_info['status'] = 'ON AIR';

    }
    return $this->radio_info;
    }

}
?>

首先,我必须指出,您不应该使用此脚本。它通过解析Icecast状态页面来工作,我们强烈反对这样做,因为它可能会改变。例如,在Icecast 2.4中,我们重新制作了完整的web界面,因此该脚本很可能会中断

实际上,您应该解析Icecast在
http://icecast.tld:8000/admin/stats
。它包含你需要的一切。如果由于某种原因无法访问Icecast的管理页面,您可以在
http://icecast.tld:8000/status-json.xsl
,它自Icecast 2.4以来就一直存在,正是为了您所描述的目的


要在不刷新的情况下让站点显示新的元数据信息,您需要使用AJAX调用,该调用可以直接加载
状态json.xsl
,提取元数据并在页面上进行更新,或者如果使用管理XML,则需要编写返回json的PHP脚本,您可以通过AJAX获取并进行相应更新。

首先,我必须指出,您不应该使用此脚本。它通过解析Icecast状态页面来工作,我们强烈反对这样做,因为它可能会改变。例如,在Icecast 2.4中,我们重新制作了完整的web界面,因此该脚本很可能会中断

实际上,您应该解析Icecast在
http://icecast.tld:8000/admin/stats
。它包含你需要的一切。如果由于某种原因无法访问Icecast的管理页面,您可以在
http://icecast.tld:8000/status-json.xsl
,它自Icecast 2.4以来就一直存在,正是为了您所描述的目的


要在不刷新的情况下让站点显示新的元数据信息,您需要使用AJAX调用,该调用可以直接加载
状态json.xsl
,提取元数据并在页面上进行更新,或者如果使用管理XML,则需要编写返回json的PHP脚本,您可以通过AJAX获取并进行相应更新。

过去很多人都谈到过设置node.js(如果您有一台服务器进行流式处理)

就我个人而言,我使用了jquery解决方案;它只是每隔10秒将最后获取的数据与实时数据进行比较。这样,它几乎“实时”加载


您可以在这里找到我的解决方案,详细说明

过去很多人都谈到过设置node.js(如果您有一台服务器进行流式处理)

就我个人而言,我使用了jquery解决方案;它只是每隔10秒将最后获取的数据与实时数据进行比较。这样,它几乎“实时”加载


您可以在这里找到我的解决方案,详细说明

谢谢您的回答。我可以进入admin/stats文件,但如何将该页面的全部信息输入我的网站?谢谢你的回答。我可以进入admin/stats文件,但如何将该页面的完整信息输入我的网站?