suresh726
suresh726

Reputation: 77

Running tasks in background in laravel 4.2

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?

Upvotes: 1

Views: 184

Answers (1)

EugeneSantos
EugeneSantos

Reputation: 368

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);

Upvotes: 2

Related Questions