Curtis
Curtis

Reputation: 2704

ping in exec() not providing correct result

When I'm trying to run the following script

$host = "ip here";
exec("/bin/ping -c2 -w2 $host", $outcome, $status); 
return print_r($outcome);

I see the following result

Array () 1

Any ideas as to why this could happen? I tried ping instead of /bin/ping to no avail

UPDATE

When running directly from SSH I'm getting shown the correct response thus being :

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

Upvotes: 1

Views: 1423

Answers (1)

fjibril
fjibril

Reputation: 86

Try redirecting std_err to std_out by appending "2>&1" and see if it says anything that helps.

exec("/bin/ping -c2 -w2 $host 2>&1", $outcome, $status); 

Depending on your configuration safe mode may only allow you to execute stuff in certain directories, or not at all.

See here: php.net/function.exec

Upvotes: 2

Related Questions