How to set the number of times to run Speedtest via PHP

Asked

Viewed 34 times

1

Hello,

I’m trying to run Speedtest on a server via PHP, I’ve installed the necessary on the server to be able to do this via Terminal on Linux, and I’ve also managed to run this test via Web access from another computer.

Accessing I have a button where his action when clicking is to perform the test and display below it an iframe, where it shows the test result when finishing the speed test.

But now, I need to put a field where I ask for the amount of times I want to do this test being 1 to 9, how can I do this ?

I created a form with an input requesting the amount of times, now I need to pass this to the request via php.

Below follows the code of the page where it contains the button that performs the test and displays the iframe, and then the code of the file that executes the test action.

function Oculta(cxa){
   if (document.getElementById(cxa).style.display=='none') {
       document.getElementById(cxa).style.display='block';
      }
   else {
      document.getElementById(cxa).style.display='none';
      location.reload();
   }
}
a.btn {
	display:inline-block;
	padding:0.3em 1.2em;
	margin:0 0.3em 0.3em 0;
	border-radius:2em;
	box-sizing: border-box;
	text-decoration:none;
	font-family:'Roboto',sans-serif;
	font-weight:300;
	color:#FFFFFF;
	background-color:#4eb5f1;
	text-align:center;
	transition: all 0.2s;
}

a.btn:hover {
	background-color:#4095c6;
}
    <form id="testes" action="" method="GET">
      <label>Quantidade de testes a serem executadas:</label>
	  <input type="tel" name="testes" maxlength="1" required>
    </form>
    <a href="speedtest.php" class="btn" target="SpeedTest" onclick="Oculta('SpeedTest')">SpeedTest</a>
    <div style="display: none;" id="SpeedTest">
      <iframe name="SpeedTest" align: center; frameborder="0"; width="800"; height="350";></iframe>
    </div>

<?php

    //shell_exec('/usr/lib/dpi/speedtest-cli.so 2>&1 | tee -a /tmp/speedtest.txt');
    shell_exec('speedtest -l');

    $output = shell_exec('cat /tmp/speedtest.txt');
    echo "<pre>$output</pre>";

?>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.