I've been working on a web interface for iPerf and it's going pretty well. My goal is to have the output of the commands be streamed live on the page. It works for iPerf2 commands but when I run iPerf3, it only shows the output once the entire test is complete.
Based on my research I've done on this site and others, I'm thinking it might have something to do with the buffer. I've been messing around with flushing the buffer at different times or setting the 'fread' length to different values but I can't get it to act the same as regular iperf commands. I think this because instead of running the 'popen' on the iperf command itself, I used popen on a python script that would run the iperf command. This still returned the same issue. It only shows the output on the web page once the entire test is complete.
Here is my code:
phpQ.php
<!DOCTYPE html>
<html>
<body>
<div>
Server Domain/IP Address: <input id="address" type="text"><br>
<input id="run" type="button" value="iPerf"><br><br>
</div>
<div id="result"></div>
<script>
function updateText(address) {
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (this.readyState == 3) {
var old_value = document.getElementById("result").innerHTML;
document.getElementById("result").innerHTML = this.responseText;
}
};
if (purpose == 1) {
var url = 'ajaxQ.php?address='+address;
ajax.open('GET', url,true);
ajax.send();
}
}
document.getElementById("run").onclick = function(){
address = document.getElementById("address").value;
purpose = 1;
updateText(address);
}
</script>
</body>
</html>
ajaxQ.php - to see the difference, change "iperf -c" to "iperf3 -c" in the $iperfCmd variable.
<?php
function liveExecuteCommand($cmd,$address)
{
while (@ ob_end_flush()); // end all output buffers if any
// tells the user what command is going to run
echo "<pre>Running Command: '".$cmd."'</pre>";
// open the command to run and read output
$proc = popen("$cmd", 'r');
$live_output = "";
$complete_output = "";
while (!feof($proc))
{
@ flush();
$live_output = fread($proc,4096);
// adds the live output to the complete output
$complete_output = $complete_output . $live_output;
// prints the live output
echo "<pre>$live_output</pre>";
}
sleep(1);
// close the process
pclose($proc);
echo "<pre>------------------------------------------------------------\nAll Done!</pre>";
}
// this happens if the iPerf button is pressed
if (isset($_GET['address'])) {
$address = $_GET['address'];
$iperfCmd = "iperf -c ".$address." -i 1 -t 5";
liveExecuteCommand($iperfCmd,$address);
}
else{
echo "No post request";
}
?>
FYI, I am running the iperf client on an 'Ubuntu 16.04.2 LTS' CLI server and the iperf server on an 'Ubuntu 16.04 LTS' desktop server.
Thanks for any help!