traviscross / mtr

Official repository for mtr, a network diagnostic tool
http://www.bitwizard.nl/mtr/
GNU General Public License v2.0
2.64k stars 337 forks source link

mtr command with php exec function in Laravel #410

Open sts-ryan-holton opened 2 years ago

sts-ryan-holton commented 2 years ago

I'm using the exec function in PHP to run the Linux mtr command (for traceroutes), but when I run it, I get a status code of 1 when I pass my domain into the command, but if I pass the --help flag or --version flag then I get a result instantly and it shows in my JSON.

How can I make the exec function essentially wait until it's returned the result of the traceroute since I fear that's the issue here?

Works: gives me a code of 0 and a result in out

$cmd = 'mtr --help';
exec($cmd, $out, $code);

Works: gives me a code of 0 and a result in out

$cmd = 'mtr --version';
exec($cmd, $out, $code);

Failing: gives me a code of 1 and no result

$cmd = 'mtr --json google.com';
exec($cmd, $out, $code);

Failing: gives me a code of 1 and no result

$cmd = 'mtr google.com';
exec($cmd, $out, $code);

If I run mtr from the command line, all the failing ones above will work as expected, granted, that a traceroute could take up-to 30 seconds to run, surely the exec waits though?

How can I resolve this?