I'm running a local dev environment using larval valet on my Mac. And I'm trying to ping a host, however I never get a response.
Running a simple shell command like "ls" works and gives the expected output.
Code
function getStatus($name) {
$ip = "1.1.1.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);
print_r($status);
}
Output:
Array ( ) 127
Since ping runs in an endless loop on *NIX systems you have to limit the number of pings that it executes. I suspect you tried to do that with the
-n
param, however, the proper one for this would be-c
which stands for "count".Therefore you should exec the ping like so:
And it works fine:
Side note: The
-n
parameter exists as well but just instructs ping to only accept numeric input - IP addresses and not hostnames.From the man page: https://ss64.com/osx/ping.html