2015-04-22 35 views
1

我有多個php腳本來ping每個位置,我試圖列出一個頁面上的所有結果。在一個陣列中處理多個PHP腳本

這裏的平腳本:

<?php 
    $host = "10.10.10.10"; //IP adress to ping 
    $loc = ("HQ"); //Name of location 
    $output = array(); 
    echo("<b>$loc</b> <i>(IP: $host)</i> is "); 
     exec("ping -n 1 $host 2>&1", $output); 
    //print_r($output); 
     //you can use print_r($output) to view the output result 
     if (count($output) > 7) { 
     $output = null; 
     die ("<font color='green'><b>up</b></font>"); 
     } 
     else { 
     $output = null; 
     die ("<font color='red'><b>down</b></font>"); 
     }  
?> 

所以,我有這個劇本,其中唯一的區別是hostloc許多PHP文件。 我一直在努力,包括在使用include這樣一個新的PHP文件的每個文件:

<?php 
include "file1.php"; 
include "file2.php"; 
include "file3.php"; 
...and so on... 
?> 

但這只是輸出的第一個文件的結果。

我怎樣才能以其他方式做到這一點?

謝謝!

+2

:簡單地改變die()echo爲英寸你應該使用'echo'而不是死亡 – Kamran

回答

4

die()或其等效exit()結束腳本。使用`die`意味着你離開你的代碼

if (count($output) > 7) { 
    $output = null; 
    echo "<font color='green'><b>up</b></font>"; 
} else {  
    $output = null; 
    echo "<font color='red'><b>down</b></font>"; 
}