2012-02-04 2 views
1

내 웹 사이트에서 라이브 스트리밍 용 웹 페이지를 만들고 있습니다.라이브 스트림 테이블이 업데이트되지 않습니다.

그러나 나는 그것에 문제가있어 테이블을 만들었고 그걸로 많이 고치고 좋은 결과를 얻었지만 아직 완벽하지는 않습니다. 그래서 저는 여전히 달라 붙음

현재 예 http://brokendiamond.org/?q=node/9;

나는 이것에 2 가지 문제가있다; 1 내 페이지가 약 2 - 3 초에로드됩니다. 여전히 약간 너무 깁니다. 2 내 테이블의 데이터가 예상대로 업데이트되지 않습니다. 내 스트림이 라이브가되면 테이블에 표시되지 않습니다. 심지어 tho 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; 
} 
?> 

답변

2

이 상쾌 아니에요 이유는 페이지가 시작될 때 <?php loadpage() ?> 만 실행하기 때문이다, 그 다음 새로 고침 (매분, 그것은 생겼다). 당신은 처음에 그것을 가지고 난 후에 매번 그 내용을 얻기 위해 다른 페이지에 요청을하고 싶을 것입니다.

jQuery를 :

지금까지 속도와 같은
$.get('yoururl.php', function(data) { /* Do stuff with `data` here */ }); 

... 그 전체 페이지에서 벌어지고있는 그 밖의 무엇? 3 가지 요청 사이에 ~ 700ms에 있습니다. 은 2/3의 두 번째로으로 끝납니다. 다른 드루팔 (Drupal) 일이 벌어지고있는 중이 야?

캐싱, 예, 할 수 있습니다! 몇가지 옵션이 있습니다 : http://en.wikipedia.org/wiki/List_of_PHP_accelerators/Memcached가 가장 강력합니다. 응답을 파일에 저장하고 파일이 1 분 미만인 경우 파일에서 읽는 다른 옵션이 있습니다. 그렇지 않으면 요청을 작성하여 덮어 씁니다. 이것은 가장 단순하며 웹 요청에서 ~ 700ms를 제거합니다.

+0

초 나를 이길! : D – Craig

+0

문제 중 하나는 페이지를 처음부터 새로 고침 (Ctrl + F5)해도 변경 사항이 표시되지 않는다는 것입니다. s – Jonathan

+0

API가 전혀 조절되지 않습니까? –

관련 문제