所以基本上,我对PHP没有任何线索,但不知何故,我设法让这个脚本工作。
(该脚本检查直播是否在线[在www.own3d.tv],如果它在线,则显示流媒体和观众的名称。如果它处于离线状态,则不显示任何内容。)
我将它插入我的Wordpress侧栏。但问题是,当我打开我的页面时,所有其他内容都会加载,但侧边栏需要几秒钟才能加载。我想检查直播需要很长时间。
那么,有没有办法让它加载更快,或者让它首先加载侧边栏上的其他内容?
在此先感谢您的回复
此致
<html>
<body>
<p style="width:300px; height:250px; padding:1px; border:5px solid #66a">
<?php
function pageTime()
{
static $_pt;
if($_pt == 0) $_pt = microtime(true);
else return (string)(round(microtime(true)-$_pt ,3));
}
pageTime();
//Froggen
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=112348");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Froggen - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/112348/">Watch now!</a> <br>';
}
else {
echo '';
}
//Athene
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=42146");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Athene - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/42146/">Watch now!</a> <br>';
}
else {
echo '';
}
//Guardsman Bob
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=34046");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Guardsman Bob - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/34046/">Watch now!</a> <br>';
}
else {
echo '';
}
//The Rain Man
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=38853");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'The Rain Man - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/38853/">Watch now!</a> <br>';
}
else {
echo '';
}
//TheOddOne
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=6416");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'TheOddOne - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/6416/">Watch now!</a> <br>';
}
else {
echo '';
}
//Dyrus
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=37905");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Dyrus - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/37905/">Watch now!</a> <br>';
}
else {
echo '';
}
//Xpecial
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=10953");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Xpecial - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/10953/">Watch now!</a> <br>';
}
else {
echo '';
}
//Chaox
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=33356");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Chaox - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/33356/">Watch now!</a> <br>';
}
else {
echo '';
}
//Wickd
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=18755");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Wickd - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/18755/">Watch now!</a> <br>';
}
else {
echo '';
}
//Lapaka
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=214");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Lapaka - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/214/">Watch now!</a> <br>';
}
else {
echo '';
}
//Snoopeh
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=112350");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Snoopeh - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/112350/">Watch now!</a> <br>';
}
else {
echo '';
}
//Dedrayon
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=265558");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Dedrayon - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/265558/">Watch now!</a> <br>';
}
else {
echo '';
}
//Malaco
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=259259");
$resultlive = $xml->xpath("/own3dReply/liveEvent/isLive");
$resultviewers = $xml->xpath("/own3dReply/liveEvent/liveViewers");
if ($resultlive[0] == 'true'){
echo 'Malaco - Viewers: '; echo ($resultviewers[0]); echo ' - <a href="http://www.own3d.tv/live/259259/">Watch now!</a> <br>';
}
else {
echo '';
}
?>
</p>
</body>
</html>
答案 0 :(得分:0)
尝试在侧边栏中创建一个简单的文本小部件,并将其粘贴到内容中。只需确保您的主题安装了jQuery:
Froggen - Viewers: <a class="live-viewers" href="http://www.own3d.tv/live/112348/">Loading...</a>
<script type='text/javascript'>
$(document).ready(function () {
$.get("http://api.own3d.tv/liveCheck.php?live_id=112348", function (res) {
var xml = $.parseXML(res);
$('.live-viewers').text(res.own3dReply.liveEvent.liveViewers[0];
});
</script>
答案 1 :(得分:0)
您应该缓存那些simplexml_load_file()调用的结果。第一次调用将花费正常的时间,但后续调用将加载缓存的数据并且执行速度非常快。