[英]check if my teamspeak server is online
I want to add a teamspeak server status checker on my website, to check if it is online or offline 我想在我的网站上添加一个Teampeak服务器状态检查器,以检查它是在线还是离线
is there a way to do it in php, or jquery, javascript or in some other way? 有没有办法在php,jquery,javascript或其他方式中做到这一点?
I tried this, in php, but it does not work... 我在php中尝试过此方法,但是它不起作用...
<?php
function check_ts($ip, $tcp, $udp, $timeout=1) { //Function for the Check
$fp = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
if (!$fp) {
$stat = false;
} else {
if (fgets($fp) == "[TS]\r\n") {
fputs($fp, "SEL $udp\r\n");
if (fgets($fp) == "OK\r\n") {
$stat = true;
} else {
$stat = false;
}
} else {
$stat = false;
}
if (is_resource($fp))
@fclose($fp);
return $stat;
}
}
if (check_ts("my_WAN_ip", 10011, 9987)) { //Change IP, Query-Port and TS-Port
echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>";
} else {
echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>";
}
?>
I've also tried different ports found in this post , but it does not work
我也尝试了在这篇文章中找到不同的端口,但是它不起作用
Please help 请帮忙
There is a Framework/Class that does exactly what you need. 有一个框架/类可以完全满足您的需求。 It's called 'TS3 PHP Framework' (see: https://www.planetteamspeak.com/ )
它被称为“ TS3 PHP框架”(请参阅: https : //www.planetteamspeak.com/ )
Example: 例:
//Load Framework
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
try {
//Connect
$ts3 = TeamSpeak3::factory("serverquery://query_user:query_pass@host:10011/?server_port=9987");
//Server Status
echo "Server Status: online";
}
catch(Exception $e) {
//Errors (No connection)
echo "Server Status: offline";
}
You can find more examples in the official documentation: http://docs.planetteamspeak.com/ts3/php/framework/ 您可以在官方文档中找到更多示例: http : //docs.planetteamspeak.com/ts3/php/framework/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.