简体   繁体   English

使用PHP查询Shoutcast服务器是脱机还是联机

[英]Query if Shoutcast Server is Offline or Online with PHP

I'm trying to use a script to query if a Shoutcast Server is online or offline. 我正在尝试使用脚本来查询Shoutcast服务器是联机还是脱机。 The code below is what I'm using at the moment. 下面的代码是我目前正在使用的代码。

$vt_ip = "ip";
$vt_port = "port";

$output = @fsockopen($vt_ip, $vt_port, $errno, $errstr, 2);

if (!$output) {
echo "<FONT CLASS=f1 COLOR=#DD0000><B>OFFLINE</B></FONT>";
} else {
echo "<FONT CLASS=f1 COLOR=#00DD00><B>ONLINE</B></FONT>";
}

@fclose($output);

But it doesn't update, it is stuck on Offline status. 但它不会更新,它停留在“脱机”状态。

Any help would be greatly appreciated. 任何帮助将不胜感激。

$vt_ip = "ip";
$vt_port = "port";

$conn = fsockopen($vt_ip, $vt_port, $errno, $errstr, 2);

if(!$conn){
    echo $errno;
}else{

fwrite($conn, "\n");
$output = fread($conn, 1024);
fclose($conn);

if ($output == "") {
    echo "<FONT CLASS=f1 COLOR=#DD0000><B>OFFLINE</B></FONT>";
} else {
        echo "<FONT CLASS=f1 COLOR=#00DD00><B>ONLINE</B></FONT>";
    }
}

It isn't enough to simply make a TCP connection to a SHOUTcast server to determine if the stream is working. 仅建立与SHOUTcast服务器的TCP连接来确定流是否正常是不够的。 In fact, a SHOUTcast server that is running will always accept yourTCP connection, even if there is no stream for playback. 实际上,即使没有播放流,正在运行的SHOUTcast服务器也将始终接受您的TCP连接。

You must connect, request the stream, and then check the return status code. 您必须连接,请求流,然后检查返回状态代码。 Once connected, send this data: 连接后,发送以下数据:

GET /; HTTP/1.0

Follow that by a \\r\\n\\r\\n . 在其后跟一个\\r\\n\\r\\n Now, read data back from the stream until you get the \\r\\n\\r\\n . 现在,从流中读回数据,直到获得\\r\\n\\r\\n为止。 Then, you can disconnect. 然后,您可以断开连接。 Check the status code from the first response line and see if it's 200 . 从第一条响应行中检查状态码,看看是否为200 If it is, you've got an active stream. 如果是的话,那么您已经有了一个活跃的流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM