我正在使用 Drupal 并想添加一个块,在其中显示用户流,就像他们在 teamliquid.net 上一样。
所以我做正常的事情,向用户添加一个字段,他们可以在其中输入他们的 Twitch-ID 等等。
所以这是我的views-view-fields--streambar--block.tpl.php 文件:
<?php
$time_pre = microtime(true);
$channelName = strip_tags($fields['field_streamid']->content);
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName)), true);
$saveResult = " is Offline";
$currentViewer = "Offline";
$game = strip_tags($fields['field_teamuser']->content);
if ($json_array['stream'] != NULL) {
$channelTitle = $json_array['stream']['channel']['display_name'];
$streamTitle = $json_array['stream']['channel']['status'];
$currentGame = $json_array['stream']['channel']['game'];
$currentViewer =$json_array['stream']['viewers']." Viewers";
$saveResult = " is Online";
}
$time_post = microtime(true);
$exec_time = $time_post - $time_pre;
$sec = $exec_time * 1000;
?>
<div class=<?php echo "\"$game streamItem\"" ?> title=<?php echo "\"$currentViewer\"" ?> >
<?php
print $sec;
print $fields['name']->content;
echo "$saveResult";
?>
</div>
到目前为止,它可以工作,但它会像地狱一样减慢网站的速度。是我的错还是 API 非常慢,我必须寻找解决方法?