PHP exec ping在Unix服务器上没有正常工作

时间:2015-11-30 09:52:07

标签: php unix server exec ping

我想ping运行Unix的服务器上的一系列ips

exec('ping -c 4 '.$ip, $output, $return_var);

问题在于,它没有正确地ping实际上被ping的ips,但是在cmd中的ns_lookup上找不到。我的意思是,其中一些ips被ping,有些则没有。在运行Windows的localhost上,它运行正常。

这是我在服务器上ping ip(运行Unix)时得到的$ output数组:

array(5) {
  [0]=>
  string(54) "PING 91.208.144.2 (91.208.144.2) 56(84) bytes of data."
  [1]=>
  string(0) ""
  [2]=>
  string(36) "--- 91.208.144.2 ping statistics ---"
  [3]=>
  string(64) "4 packets transmitted, 0 received, 100% packet loss, time 2999ms"
  [4]=>
  string(0) ""
}

我在localhost(在Windows上)ping它时获得的$ output数组:

array(11) {
  [0]=>
  string(0) ""
  [1]=>
  string(43) "Pinging 91.208.144.2 with 32 bytes of data:"
  [2]=>
  string(50) "Reply from 91.208.144.2: bytes=32 time=9ms TTL=248"
  [3]=>
  string(51) "Reply from 91.208.144.2: bytes=32 time=10ms TTL=248"
  [4]=>
  string(51) "Reply from 91.208.144.2: bytes=32 time=11ms TTL=248"
  [5]=>
  string(50) "Reply from 91.208.144.2: bytes=32 time=8ms TTL=248"
  [6]=>
  string(0) ""
  [7]=>
  string(33) "Ping statistics for 91.208.144.2:"
  [8]=>
  string(56) "    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),"
  [9]=>
  string(46) "Approximate round trip times in milli-seconds:"
  [10]=>
  string(48) "    Minimum = 8ms, Maximum = 11ms, Average = 9ms"
}

exec和ping在服务器上可用,因为它与被ping的ips完美配合,可以在cmd中查找。

有什么想法吗?

0 个答案:

没有答案