找到代碼在一個簡單的例子:
$ip = "192.168.0.2";
$exec = exec("ping -c 3 -s 64 -t 64 ".$ip, $output, $return);
echo $exec;
echo "<br />----------------<br />";
print_r($output);
echo "<br />----------------<br />";
print_r($return);
在無法ping或錯誤的情況下。 (一)
----------------
Array ([0] => PING 192.168.0.2 (192.168.0.2) 64(92) bytes of data. [1] => [2] => --- 192.168.0.2 ping statistics --- [3] => 3 packets transmitted, 0 received, 100% packet loss, time 2016ms [4] =>)
----------------
1
在成功(ZERO)
rtt min/avg/max/mdev = 4.727/18.262/35.896/13.050 ms
----------------
Array ([0] => PING 192.168.0.2 (192.168.0.2) 64(92) bytes of data. [1] => 72 bytes from 192.168.0.2: icmp_req=1 ttl=63 time=14.1 ms [2] => 72 bytes from 192.168.0.2: icmp_req=2 ttl=63 time=35.8 ms [3] => 72 bytes from 192.168.0.2: icmp_req=3 ttl=63 time=4.72 ms [4] => [5] => --- 192.168.0.2 ping statistics --- [6] => 3 packets transmitted, 3 received, 0% packet loss, time 2003ms [7] => rtt min/avg/max/mdev = 4.727/18.262/35.896/13.050 ms)
----------------
0
爲什麼不檢查創建的文件,看看它是否有效? – 2012-08-09 02:16:42
你是否檢查過你的系統中是否啓用了'exec()'? – deex 2012-08-09 02:17:19
Exec返回輸出的最後一行,這必須在PHP中等同於true。 – 2012-08-09 02:18:48