Livestream表没有像它应该的那样更新

时间:2012-02-04 00:02:24

标签: php javascript html live-streaming

我正在为我的网站上的livestreamers建立一个网页。

但是我遇到了一些问题,我已经创建了一张桌子,而且我一直在用它拧了很多而且我有很好的效果,但它还不完美,所以我还是卡住了

当前示例http://brokendiamond.org/?q=node/9;

我遇到了2个问题; 1我的页面加载大约2 - 3秒,仍然有点太长 2我的表中的数据没有像我们想象的那样更新,当我的流上线时,它没有显示在我的表中,即使xml文件确实得到更新,也没有正确显示视图计数,所以有一些问题,

任何有关此事的输入,或对此问题的帮助都将不胜感激,因为我真的想完成这部分,所以我可以继续我的待办事项清单。

我听过人们谈论现金,但我不知道如何做到这一点,这可能是一个方向。

可以在以下位置找到XML API: http://api.own3d.tv/liveCheck.php?live_id=210230

我的网页的当前代码是:

Hello and welcome to the Livestream page for the broken diamond community here you can find all our content creator's livestream pages to watch them game. you can chat with other members and even them! We always welcome new followers and will love to hear about suggestions for games, in game tips and all those opinions we know you have to share! Enjoy your favorite streamers, and don't forget their schedule can be found under the information block in the menu.
<div id="livetable">

</div>

<script type="text/javascript">  
load();
var intervalID;  
refresh();
function refresh()  
{  
  intervalID = setInterval(load, 60000);  
}  

function load()  
{  
  var elem = document.getElementById("livetable");
  elem.innerHTML = '<?php loadpage() ?><br>';
}  
</script>

<?php
define('ELEMENT_CONTENT_ONLY', true);
define('ELEMENT_PRESERVE_TAGS', false);

function value_in($element_name, $xml, $content_only = true) 
{
    if ($xml == false)
    {
        return false;
    }
    $found = preg_match('#<'.$element_name.'(?:\s+[^>]+)?>(.*?)'.'</'.$element_name.'>#s', $xml, $matches);
    if ($found != false) 
    {
        if ($content_only) 
        {
            return $matches[1];  //ignore the enclosing tags
        }
       else 
       {
            return $matches[0];  //return the full pattern match
        }
    }
    // No match found: return false.
    return false;
}

function loadpage()
{
      echo "<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 95%\" >";
      echo "<tr class=\"info-row\" bgcolor=#252525 style=\"color:white;  height: 15px;\">";
      echo "<td style=\"width: 14%; height: 10px; padding-left: 5px;\"><b>Preview</b></td>";
      echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Live</b></td>";
      echo "<td style=\"width: 36%; height: 10px; padding-left: 5px;\"><b>Stream</b></td>";
      echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Viewers</b></td>";
      echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Time online</b></td>";
      echo "</tr>";
      addrow(107473,10,"Osuryn","Osuryn is streaming random games live",false);
      addrow(210320,28,"Dennojj","Dennojj is streaming PS3 games",true);
      echo "</table>";
}

function addrow($streamID, $streamPage , $streamName , $streamSlogan, $odd)
{
     if ($odd)
     {
            echo "<tr class=\"content-row online\" id=\"958\" bgcolor=#A7A7A7>";
     }
     else
     {
            echo "<tr class=\"content-row online\" id=\"958\" bgcolor=#BFBFBF>";
     }
     echo "<td style=\"width: 14%;\"><img src=\"http://img.hw.own3d.tv/live/live_tn_".$streamID."_.jpg\" style=\"height: 72px;\" \></td>";
     echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br><b>".getLiveStatus($streamID)."</b></td>";
     echo "<td style=\"width: 36%; vertical-align: top; padding-top: 6px; padding-right: 6px;\">";
     echo "<div><br><a href=\"http://brokendiamond.org/?q=node/$streamPage\">$streamName</a></div>";
     echo "<div style=\"padding-top: 6px; font-size: 11px;\">$streamSlogan</div>";
     echo "</td>";
     echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br>".getLiveViews($streamID)."</td>";
     echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br>".getOnTime($streamID)." minutes online</td>";
     echo "</tr>";
}

function getLiveStatus($streamID)
{
    $request =  'http://api.own3d.tv/liveCheck.php?live_id='.$streamID;
    $arg = '240';

    $session = curl_init($request.$arg);

    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($session);
    curl_close($session);

    if (preg_match("/true/",$response, $result)) 
    {
        $streamStatus="Live";
    } 
    else 
    {
      $streamStatus="Offline";
    }
    return $streamStatus;
}

function getLiveViews($StreamID)
{
    $request =  'http://api.own3d.tv/liveCheck.php?live_id='.$StreamID;
    $arg = '240';

    $session = curl_init($request.$arg);

    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($session);
    curl_close($session);

    $viewStatus =value_in('liveViewers', $response) + "";

    return $viewStatus;
}

function getOnTime($StreamID)
{
    $request =  'http://api.own3d.tv/liveCheck.php?live_id='.$StreamID;
    $arg = '240';

    $session = curl_init($request.$arg);

    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($session);
    curl_close($session);

    $onStatus =value_in('LiveDuration', $response) + "";

    return $onStatus;
}
?>

1 个答案:

答案 0 :(得分:2)

它不刷新的原因是因为<?php loadpage() ?>仅在页面启动时运行,而不是任何后续刷新(每分钟,它看起来像)。您希望在最初拥有该内容之后向其他页面发出请求以获取该内容。

jQuery的:

$.get('yoururl.php', function(data) { /* Do stuff with `data` here */ });

就速度而言......整个页面还有什么?在3个请求之间,你需要大约700毫秒,其中关闭到2/3的第二个,但不完全。我假设还有一些其他的drupal东西在继续吗?

缓存,是的,那样做!您有几种选择: http://en.wikipedia.org/wiki/List_of_PHP_accelerators / Memcached是最强大的。还有另一种方法可以保存对文件的响应,如果文件不到一分钟,则从文件中读取,否则请发出请求并覆盖它。这将是最简单的,并将删除Web请求中的~700ms。