1

I have a condition where I have to start iperf server as daemon on specified port and if iperf server is running, I have to send response to client. I tried

shell_exec('iperf -s -p {port} -D'); 

but it doesn't return control / infinite loop starts. The server will start but the code below the shell_exec will never be executed. Anyone has a solution or suggestion how I should approach this to get the result?

1 Answer 1

2

Your command iperf -s -p {port} -D happens to have stderr output, try doing this:

$outfile = "/tmp/erroutperf.out";
$port = 8080;
shell_exec("iperf -s -p $port -D > $outfile 2>&1");

basically the additional command > /tmp/erroutperf.out 2>&1, tells bash to save both stderr output and stdout of a program (iperf) to a file /tmp/erroutperf.out

getting the output of the command is:

file_get_contents($outfile);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.