因此,我試圖更新下面的代碼,它監視icecast和shoutcast監聽器,因爲當我升級到shoutcast 2時,它停止工作,作者是AWOL或至少不選擇回答。更新munin shoutcast監控插件代碼從版本1到2
現在我認爲我已經解決了正則表達式的問題,但它仍然無法正常工作。這讓我想到代碼檢索狀態頁面和新URL格式的方式也是一個問題。
無論如何,我將不勝感激任何幫助,你可以給我試圖解決如何解決這個問題,謝謝!
從管線158中的舊的正則表達式:
preg_match_all("/.*?Stream Status: \<\/td\>\<td\>\<b\>\Stream is up at \d*? kbps with (\d*?) of \d*? listeners\<\/b\>\<\/td\>\<\/tr\>/s", $xml, $parser);
我的第一個正則表達式:
preg_match_all("/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at (\d*?) kbps with \<B\>(\d*?) of (\d*?) listeners/s", $xml, $parser);
問題代碼:
function getShout($host, $port, $name) {
$error = false;
$fp = fsockopen($host, $port, $errno, $errstr, 10);
if (!$fp) {
$error = $errstr ."(". $errno .")";
} else {
fputs($fp, "GET/HTTP/1.0\r\n");
fputs($fp, "User-Agent: Mozilla\r\n");
fputs($fp, "Connection: close\r\n\r\n");
$xml = "";
while (!feof($fp)) {
$xml .= fgets($fp, 512);
}
fclose($fp);
if (stristr($xml, "HTTP/1.0 200 OK") == true) {
$xml = trim(substr($xml, 42));
} else {
$error = "Bad login";
}
if (!$error) {
$res = array("found" => true);
preg_match_all("/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at (\d*?) kbps with \<B\>(\d*?) of (\d*?) listeners/s", $xml, $parser);
$res["listeners"] = $parser[1][0];
$res["name"] = $name;
} else {
$res = $error;
}
}
return $res;
}
的OU tput的我從在命令行運行插件得到...
rock.value B
pop.value B
rap.value B
dnb.value B
psytrance.value B
breaks.value B
dubstep.value B
reggae.value B
techno.value B
ambient.value B
complete.value 0
樣品Shoutcast的V1狀態頁:http://stream.radioamlo.info:8010/
樣品Shoutcast的V2狀態頁:http://91.221.151.237:8994/index.html?sid=1
更新#1 :我的第二個正則表達式看起來更好:
preg_match_all("/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at \d*? kbps with \<B\>(\d*?) of \d*?
UPDATE#2:添加'echo $ xml;' '$ error =「Bad login」後';'返回以下錯誤:
<html><head><title>Redirect</title></head><body>Click <a href="/index.html?sid=1">here</a> for redirect.</body></html>techno.value B
HTTP/1.1 302 Found
Content-Type:text/html;charset=utf-8
Location:index.html?sid=1
Content-Length:118
請問您可以發佈$ xml的示例輸出嗎? – fjellfly
對不起,我該如何生成? –
例如在帶有preg_match_all的行之後帶有'echo $ xml'。 – fjellfly