[英]Undefined Variable by running a script on PHP 5.4 and IIS 8
I have a small question about running a script on windows ( IIS 8 + PHP 5.4 ) I try to make the script below to work. 我有一个关于在Windows(IIS 8 + PHP 5.4)上运行脚本的小问题,我试图使下面的脚本正常工作。
<?php
class RadInfo {
private $db;
private $cfg;
private $dnas_data;
function __construct() {
$this->db = Com_DB::getInstance();
$this->cfg = new Config();
}
function openstats() {
$ch = curl_init($this->cfg->shoutcasthost . '/admin.cgi?sid=' . $this->cfg->shoutcastsid . '&mode=viewxml');
curl_setopt($ch, CURLOPT_PORT, $this->cfg->shoutcastport);
curl_setopt($ch, CURLOPT_USERAGENT, $this->cfg->shoutcastuagent);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->cfg->shoutcastuser . ':' . $this->cfg->shoutcastpasswd);
$curl = curl_exec($ch);
curl_close($ch);
if ($curl) {
$xml = @simplexml_load_string($curl);
$dnas_data = array (
'CURRENTLISTENERS' => $xml->CURRENTLISTENERS,
'PEAKLISTENERS' => $xml->PEAKLISTENERS,
'MAXLISTENERS' => $xml->MAXLISTENERS,
'REPORTEDLISTENERS' => $xml->REPORTEDLISTENERS,
'AVERAGETIME' => $xml->AVERAGETIME,
'SERVERGENRE' => $xml->SERVERGENRE,
'SERVERURL' => $xml->SERVERURL,
'SERVERTITLE' => $xml->SERVERTITLE,
'SONGTITLE' => $xml->SONGTITLE,
'NEXTTITLE' => $xml->NEXTTITLE,
'SONGURL' => $xml->SONGURL,
'IRC' => $xml->IRC,
'ICQ' => $xml->ICQ,
'AIM' => $xml->AIM,
'STREAMHITS' => $xml->STREAMHITS,
'STREAMSTATUS' => $xml->STREAMSTATUS,
'BITRATE' => $xml->BITRATE,
'CONTENT' => $xml->CONTENT,
'VERSION' => $xml->VERSION,
);
if ($dnas_data['STREAMSTATUS'] == 1)
{
foreach ($xml->LISTENERS->LISTENER as $listener)
{
$sc_data['LISTENERS'][] = array(
'HOSTNAME' => $listener->HOSTNAME,
'USERAGENT' => $listener->USERAGENT,
'CONNECTTIME' => $listener->CONNECTTIME,
'POINTER' => $listener->POINTER,
'UID' => $listener->UID,
);
}
foreach ($xml->SONGHISTORY->SONG as $song)
{
$sc_data['SONGHISTORY'][] = array(
'PLAYEDAT' => $song->PLAYEDAT,
'TITLE' => $song->TITLE,
);
}
}
} else {
$dnas_data = array('ERROR' => 'Could not connect to dnas-server!');
}
}
function LoadServerTitle() {
return $this->dnas_data['STREAMTITLE'];
}
}
?>
I have made changes to the script but the output stays on this moment NULL. 我已对脚本进行了更改,但此刻输出仍为NULL。
I have tried to call the class/function thought: 我试图称呼类/函数为:
$comcms->slim->get('/streamtitle', function() use($comcms) {
$comcms->jsonOutput($comcms->radinfo->LoadServerTitle());
});
and 和
$comcms->slim->get('/streamtitle', function() use($comcms) {
if ($comcms->radinfo->openstats()) {
$comcms->jsonOutput($comcms->radinfo->LoadServerTitle());
}
});
I have tried several options but noting work. 我尝试了几种选择,但注意了工作。 I had first problems with cURL but that is solved because PHP fail to load the module.
我在使用cURL时遇到了第一个问题,但由于PHP无法加载模块,因此可以解决。
Now i have problems getting any information. 现在我在获取任何信息时遇到问题。 The LoadServerTitle gives a output that says NULL but i cant get it to work properly.
LoadServerTitle提供的输出显示为NULL,但我无法使其正常工作。 The $this->cfg part comes out the database.
$ this-> cfg部分来自数据库。
Can someone give me a idea to get this script working. 有人可以给我一个让此脚本起作用的想法。 I want to thank the people that help me so far.
我要感谢到目前为止帮助我的人们。
You declare $dnas_data
in a method, so it won't be accessible outside that method. 您在方法中声明了
$dnas_data
,因此在该方法之外将无法访问它。
I would suggest you to declare another member variable for storing the data: 我建议您声明另一个用于存储数据的成员变量:
class RadInfo {
private $db;
private $cfg;
private $dnas_data;
And replace every occurrence of $dnas_data
by $this->dnas_data
并用
$this->dnas_data
替换每次出现的$dnas_data
$this->dnas_data
I just looked again at your GetServerTitle()
method: 我只是再次查看了您的
GetServerTitle()
方法:
return($this->openstats($dnas_data['SERVERTITLE']));
Do you really want to call openstats()
again? 您是否真的要再次调用
openstats()
? Change this to : 更改为:
return $this->dnas_data['SERVERTITLE'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.