You can use AJAX to make your requests to this PHP file, preventing the page from being reloaded every 50 seconds.
The advantage of using AJAX is that you reduce traffic between the client and the server and consequently reduce the processing load on the server.
Instead of reloading all the content, you will only receive the response from the request, which in your case will probably be an array with the CPU load data. With the response of the request, you will just have to update some elements of your HTML with the updated information.
Use with the Long Polling technique, so it will only reorder the server if there is a change in the request response.
See this link: ajax analysis .
The question is about analyzing an AJAX code, it can be used as an example, you will see some analysis, it is already out of the context of your question, but it is indirectly linked.
Example with pure Javascript:
On your page where the refresh is done every 50 seconds, enter the following code:
<script type="text/javascript">
o = "";
try{ o = new XMLHttpRequest() }
catch(e){ o = new ActiveXObject("Microsoft.XMLHTTP"); }
function getAjax(){
//Troque "seu_ficheiro.php" pelo seu ficheiro PHP que verifica a carga do CPU
//Nesse exemplo, o ficheiro PHP está no mesmo directório que o HTML onde foi inserido o Javascript, se estiver em directórios diferentes, é necessário inserir o caminho correcto.
o.open("GET","seu_ficheiro.php",true);
o.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
o.onreadystatechange = function(){
if(o.readyState == 4){
//Altera somente o HTML da div que vai receber a resposta da requisição
//No exemplo utilizamos a div com o id "resultado"
document.getElementById("resultado").innerHTML = o.responseText;
}
}
o.send(null);
}
//A cada 10 segundos será feito uma nova requisição ao servidor
setTimeout("getAjax()",10000);
</script>
In your PHP file, you have an "echo" of the variable "$ data", in the "result" div the content of the "$ data" variable should appear.
This is a basic example of an AJAX request, it should not be used on a large scale to avoid overloading the server.
Do not forget to remove the refresh every 50 seconds, it will no longer be necessary.