我的問題是我一個數組值設置爲服務器如下的名稱:PHP從不爲file_exists測試真正在評估數組值
$appserver[$i]=`grep $ip[2] /etc/hosts |awk '{print $2}'`;
後來我做一個測試,看看服務器上或不(使用wget)。 如果測試失敗我跟蹤該服務器通過與 名稱中使用觸摸創建文件是下來的:
$touch=`touch /home/steve/data/$appserver[$i];
文件被創建成功。 稍後,當我去測試文件是否存在時,它永遠不會計算爲true。
if(file_exists('/home/steve/data/$appserver[$i])) {
我已經嘗試了幾種不同的東西,包括對 $應用程序服務器[$ i]和測試反對它,它也不起作用創建一個新的變量:
我在RHEL上運行PHP 5.1.6 5.
下面是完整的代碼:
$appserver[$i]=`grep $ip[2] /etc/hosts |awk '{print $2}'`;
echo "appserver[i] = $appserver[$i]\n";
$get=`wget $key->url 2> /dev/null`;
if(file_exists('/home/user/Start')) {
$color[$i]="green";
$rm=`rm -rf /home/user/Start`;
}
else {
$color[$i]="red";
if($hostname=="xxxxx") {
**if(file_exists('/home/user/data/$appserver[$i]))** {**
echo "do nothing appserver file exists\n";
$touch=`touch /home/steve/data/notmailed`;
}
else {
echo "No app file mailed alert\n";
$touch=`touch /home/user/data/$appserver[$i]`;
}
}
}
謝謝。
''$應用程序服務器[$ i] = 「$應用程序服務器[$ i]」' – raina77ow