Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在exec()中ping未提供正确的结果_Php_Exec - Fatal编程技术网

Php 在exec()中ping未提供正确的结果

Php 在exec()中ping未提供正确的结果,php,exec,Php,Exec,当我尝试运行以下脚本时 $host = "ip here"; exec("/bin/ping -c2 -w2 $host", $outcome, $status); return print_r($outcome); 我看到了以下结果 Array () 1 你知道为什么会这样吗?我尝试了ping而不是/bin/ping,但没有成功 更新 直接从SSH运行时,我会看到正确的响应,因此: PING ip here 56(84) bytes of data. 64 bytes from ip h

当我尝试运行以下脚本时

$host = "ip here";
exec("/bin/ping -c2 -w2 $host", $outcome, $status); 
return print_r($outcome);
我看到了以下结果

Array () 1
你知道为什么会这样吗?我尝试了
ping
而不是
/bin/ping
,但没有成功

更新

直接从SSH运行时,我会看到正确的响应,因此:

PING ip here 56(84) bytes of data.
64 bytes from ip here : icmp_seq=1 ttl=243 time=4.47 ms
64 bytes from ip here : icmp_seq=2 ttl=243 time=4.40 ms

--- ip here ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1005ms
rtt min/avg/max/mdev = 4.406/4.438/4.470/0.032 ms

尝试通过附加“2>&1”将std_err重定向到std_out,看看它是否有帮助

exec("/bin/ping -c2 -w2 $host 2>&1", $outcome, $status); 
根据您的配置,安全模式可能只允许您执行某些目录中的内容,或者根本不允许


请参见此处:

从命令行尝试相同操作时会发生什么?它有效吗,或者你仍然得到不正确的结果(或者没有结果)?如果是后者,那么这是命令本身(或标志)的问题。我已经继续并更新了我的问题,感谢您通知我使用命令行进行测试。谢谢工作,它产生了我需要修复的错误,我需要在找到错误后
Ping:icmp open socket:Operation not allowed